System Design + Inheritance
Stacks, Queues, and Heaps
Graphs
Trees + Tries
Dynamic Programming
100

This OOP principle bundles data and methods together in a class and restricts direct access using modifiers like private and public.

What is Encapsulation?

100

This data structure follows the “Last In, First Out” principle.

What is a Stack?

100

What is a cycle in a graph?

What is a path that returns to the starting node without reusing edges?

100

Which traversal visits nodes in this order: root -> left -> right?

What is preorder traversal?

100

What is the main idea of dynamic programming?

What is breaking problems into smaller subproblems and reusing results?

200

In system design, why might you trade space complexity for time complexity?

What is
to speed up operations using extra memory (like caching or hashmaps)?

200

What stack pattern is used to solve “next greater element” problems?

What is a monotonic stack?

200

What is the key difference between a tree and a general graph?

What is a tree has no cycles (is acyclic)?

200

What property makes recursion a natural fit for tree problems?

What is trees are made of smaller subtrees (recursive structure)?

200

What is the difference between memoization and tabulation?

What is

memoization = top-down (recursion), tabulation = bottom-up (iteration)?

300

What is the difference between method overloading and method overriding?

What is

overloading = same method name, different parameters;
overriding = redefining a parent class method in a subclass
?

300

Why is a heap preferred over sorting every time when repeatedly retrieving the smallest or largest element?

What is because heap operations are O(log n), faster than repeatedly sorting O(n log n)?

300

What is the time complexity of BFS or DFS on a graph with V vertices and E edges?

What is O(V + E)?

300

What is a trie primarily used for?

What is storing and searching strings efficiently (by prefix)?

300

What does dp[i] typically represent in DP problems?

What is the solution to a subproblem up to index i?

400

You need to design a data structure that supports insert, remove, and getRandom in average O(1) time.
What TWO data structures should you combine to achieve this?

What are an Array/List + a HashMap?

400

In backtracking, why do we “undo” a choice before trying the next option?

What is to return to a previous state and explore other possibilities?

400

In Kahn’s algorithm, what does it mean if not all nodes are processed?

What is a cycle exists in the graph?

400

In level order traversal:

for i in range(len(queue)):
    node = queue.popleft()

Why do we use len(queue) here?

What is to process one level at a time?

400

In Edit Distance, what does dp[i][j] represent?


What is the minimum operations to convert first i chars to first j chars?

500

You are designing Twitter and use a heap to keep track of the most recent tweets.


If you process n tweets and keep only the top k most recent ones in the heap, what is the time complexity?

What is O(n log k)?

500

In the Daily Temperatures problem, we use a stack to store indices of days that have not found a warmer day yet.

while stack and temperatures[i] > temperatures[stack[-1]]:
    j = stack.pop()
    daysWaited[j] = i - j

What does i - j represent?

What is the number of days day j has to wait until a warmer temperature?

500

You are using BFS to find the shortest path in an unweighted graph:

queue = deque([start])
visited = set()

while queue:
    node = queue.popleft()
    for neighbor in graph[node]:
        if neighbor not in visited:
            queue.append(neighbor)

What is the issue with this implementation?

What is nodes are not marked as visited when added, so they may be added to the queue multiple times and potentially cause infinite loops?

500

This DFS is meant to traverse a tree:

def dfs(node):
    if not node:
        return
    dfs(node.left)
    dfs(node.right)

What is the bug?

What is it never processes the node (missing visit/output step)?

500

What is the bug here?

dp = [0] * (n+1)
for i in range(n+1):
    dp[i] = dp[i-1] + dp[i-2]

What is missing base cases (dp[0], dp[1])?

M
e
n
u