Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: Classic DP is O(n²): dp[i] = best LIS ending at i. The optimized patience-sorting / binary-search approach maintains tails of increasing subsequences in O(n log n). Mention both; implement O(n²) unless aske…
Short answer: Hash map from key → node plus a doubly linked list ordered by recency. get/put are O(1): move accessed node to front; on capacity eviction remove from tail. This is one of the most asked system-design-lite…
Short answer: Use preorder with null markers (e.g. "#") or level-order BFS with nulls. Deserialization consumes the same format with a queue/iterator. Clarify the string format with the interviewer first. Complexity Time…
Short answer: Water at i is min(leftMax, rightMax) − height[i]. Compute with two arrays, or optimize with two pointers moving from ends while tracking leftMax/rightMax. Stack-based solution processes bars as histogram va…
Short answer: Monotonic deque storing indices in decreasing height order. As the window slides, pop out-of-window indices from front and smaller values from back. Front is always the max. O(n). Complexity Time O(n), Spac…
Short answer: Model words as graph nodes; edges connect words differing by one letter. BFS from beginWord finds shortest transformation length. Bidirectional BFS is a strong optimization follow-up. Complexity Time roughl…
Short answer: 2-D DP: if s[i]==t[j], dp[i][j] = dp[i-1][j-1]+1 else max(skip either char). Classic O(m*n) table; can compress to two rows for space. Common follow-ups Print the LCS string Longest Common Substring (differ…
DSA & Coding Interviews Coding Interview FAQ · Dynamic Programming
Short answer: Classic DP is O(n²): dp[i] = best LIS ending at i. The optimized patience-sorting / binary-search approach maintains tails of increasing subsequences in O(n log n). Mention both; implement O(n²) unless asked for optimal.
DP O(n²); patience sorting O(n log n).
Interviewers love hearing both complexities even if you code the simpler DP.
DSA & Coding Interviews Coding Interview FAQ · Design
Short answer: Hash map from key → node plus a doubly linked list ordered by recency. get/put are O(1): move accessed node to front; on capacity eviction remove from tail. This is one of the most asked system-design-lite coding questions.
get/put O(1) average; Space O(capacity).
In C#, LinkedList + Dictionary is the standard interview implementation.
DSA & Coding Interviews Coding Interview FAQ · Trees
Short answer: Use preorder with null markers (e.g. "#") or level-order BFS with nulls. Deserialization consumes the same format with a queue/iterator. Clarify the string format with the interviewer first.
Time O(n), Space O(n).
Pick one format and stick to it — inconsistency is a common fail point.
DSA & Coding Interviews Coding Interview FAQ · Two Pointers / Stack
Short answer: Water at i is min(leftMax, rightMax) − height[i]. Compute with two arrays, or optimize with two pointers moving from ends while tracking leftMax/rightMax. Stack-based solution processes bars as histogram valleys.
Two pointers O(n) time, O(1) space.
Relate it to Container With Most Water but stress per-index water units.
DSA & Coding Interviews Coding Interview FAQ · Deque / Sliding Window
Short answer: Monotonic deque storing indices in decreasing height order. As the window slides, pop out-of-window indices from front and smaller values from back. Front is always the max. O(n).
Time O(n), Space O(k).
This is a classic “monotonic queue” question — name the pattern.
DSA & Coding Interviews Coding Interview FAQ · Graphs / BFS
Short answer: Model words as graph nodes; edges connect words differing by one letter. BFS from beginWord finds shortest transformation length. Bidirectional BFS is a strong optimization follow-up.
Time roughly O(N * L * 26) with wildcards or neighbor generation.
BFS = shortest path in unweighted graph — say that sentence.
DSA & Coding Interviews Coding Interview FAQ · Dynamic Programming
Short answer: 2-D DP: if s[i]==t[j], dp[i][j] = dp[i-1][j-1]+1 else max(skip either char). Classic O(m*n) table; can compress to two rows for space.
Contrast subsequence (not contiguous) vs substring (contiguous) immediately.