Interview Preparation Guide - Full Topics Q&A
1. Python
Q1: Difference between @staticmethod and @classmethod?
- @staticmethod: No access to class or instance
- @classmethod: Has cls parameter to access class
Q2: How does Python handle memory management?
- Automatic garbage collection
- Reference counting and generational GC
Q3: Python function to check anagram:
def is_anagram(s1, s2):
return sorted(s1) == sorted(s2)
Q4: Output of:
x = [1, 2, 3]
y=x
[Link](4)
print(x)
# Output: [1, 2, 3, 4]
2. Data Structures
Q1: How does a stack work? Example.
- LIFO (Last In First Out)
- Real-life: Stack of plates
Q2: Time complexity of search in BST?
- Average: O(log n)
- Worst: O(n)
Q3: Queue using two stacks implementation:
class QueueUsingStacks:
def __init__(self):
self.s1 = []
self.s2 = []
def enqueue(self, x):
[Link](x)
def dequeue(self):
Interview Preparation Guide - Full Topics Q&A
if not self.s2:
while self.s1:
[Link]([Link]())
return [Link]() if self.s2 else None
Q4: Difference between linked list and array?
| Feature | Array | Linked List |
| Memory | Contiguous | Non-contiguous |
| Access | O(1) | O(n) |
| Insertion | Costly | O(1) at head |
3. Algorithms
Q1: Find first non-repeating character:
from collections import Counter
def first_unique(s):
count = Counter(s)
for ch in s:
if count[ch] == 1:
return ch
return None
Q2: BFS vs DFS?
- BFS uses queue (level-order)
- DFS uses stack/recursion (depth-first)
Q3: Greedy algorithm?
- Locally optimal choices
- Example: Activity selection
Q4: Kadane's Algorithm (max subarray sum):
def kadane(arr):
max_current = max_global = arr[0]
for x in arr[1:]:
max_current = max(x, max_current + x)
max_global = max(max_global, max_current)
return max_global
4. DBMS
Interview Preparation Guide - Full Topics Q&A
Q1: WHERE vs HAVING?
- WHERE: filter rows before grouping
- HAVING: filter groups after grouping
Q2: Employees earning more than avg salary:
SELECT name FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
Q3: Explain 3NF:
- Table in 2NF with no transitive dependency
Q4: Transactions:
- Group of SQL statements satisfying ACID
5. Operating Systems
Q1: Process vs Thread?
| Feature | Process | Thread |
| Memory | Separate | Shared |
| Speed | Slower | Faster |
Q2: Context switching?
- Saving/restoring CPU state to switch processes
Q3: Deadlock?
- Circular waiting for resources; avoid by ordering or timeout
Q4: Virtual memory?
- Uses disk space as RAM extension for multitasking
6. Computer Networks
Q1: TCP vs UDP?
| Feature | TCP | UDP |
| Reliable | Yes | No |
| Ordered | Yes | No |
| Speed | Slower | Faster |
Q2: TCP 3-way handshake:
1. SYN
Interview Preparation Guide - Full Topics Q&A
2. SYN-ACK
3. ACK
Q3: DNS?
- Converts domain names to IP addresses
Q4: HTTP vs HTTPS?
- HTTPS adds encryption (SSL/TLS)