Interview Q&A · questions with model answers
Data Structures Interview Questions
Part of the study plan for: Machine Learning Engineer
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked How would you approach the classic problem 'two-sum'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'two-sum'.
-
Most asked How would you approach the classic problem 'merge intervals'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'merge intervals'.
-
Most asked How would you approach the classic problem 'group anagrams'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'group anagrams'.
-
Most asked How would you approach the classic problem 'valid parentheses'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'valid parentheses'.
-
Most asked How would you approach the classic problem 'binary tree level order'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'binary tree level order'.
-
Most asked How would you approach the classic problem 'longest substring without repeating'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'longest substring without repeating'.
-
Most asked How would you approach the classic problem 'number of islands'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'number of islands'.
-
Most asked How would you approach the classic problem 'kth largest element'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'kth largest element'.
-
Most asked How would you approach the classic problem 'top k frequent'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'top k frequent'.
-
How would you approach the classic problem 'invert binary tree'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'invert binary tree'.
-
How would you approach the classic problem 'course schedule'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'course schedule'.
-
How would you approach the classic problem 'coin change'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'coin change'.
-
How would you approach the classic problem 'product except self'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'product except self'.
-
How would you approach the classic problem 'clone graph'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'clone graph'.
-
How would you approach the classic problem 'trapping rain water'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'trapping rain water'.
-
How would you approach the classic problem 'serialize/deserialize tree'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'serialize/deserialize tree'.
-
How would you approach the classic problem 'implement trie'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'implement trie'.
-
How would you approach the classic problem 'search rotated array'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'search rotated array'.
-
How would you approach the classic problem 'meeting rooms'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'meeting rooms'.
-
How would you approach the classic problem 'palindrome linked list'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'palindrome linked list'.
-
How would you approach the classic problem 'spiral matrix'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'spiral matrix'.
-
How would you approach the classic problem 'house robber'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'house robber'.
-
How would you approach the classic problem 'unique paths'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'unique paths'.
-
How would you approach the classic problem 'minimum window substring'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'minimum window substring'.
-
How would you approach the classic problem 'daily temperatures'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'daily temperatures'.
-
How would you approach the classic problem 'asteroid collision'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'asteroid collision'.
-
How would you approach the classic problem 'flatten nested list'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'flatten nested list'.
-
How would you approach the classic problem 'lowest common ancestor'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'lowest common ancestor'.
-
How would you approach the classic problem 'word break'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'word break'.
-
How would you approach the classic problem 'merge k sorted lists'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'merge k sorted lists'.
-
How would you approach the classic problem 'median of two sorted arrays'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'median of two sorted arrays'.
-
How would you approach the classic problem 'design hit counter'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'design hit counter'.
-
How would you approach the classic problem 'find peak element'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'find peak element'.
-
How would you approach the classic problem 'alien dictionary'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'alien dictionary'.
-
How would you approach the classic problem 'add two numbers'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'add two numbers'.
-
How would you approach the classic problem 'rotate image'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'rotate image'.
-
How would you approach the classic problem 'jump game'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'jump game'.
-
How would you approach the classic problem 'edit distance'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'edit distance'.
-
How would you approach the classic problem 'sliding window maximum'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'sliding window maximum'.
-
How would you approach the classic problem 'next greater element'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'next greater element'.
-
How would you approach the classic problem 'decode string'?
Clarify constraints, identify the right pattern (two pointers, BFS/DFS, heap, DP, etc.), state time/space complexity, and discuss edge cases for 'decode string'.