DSA

Top DSA Interview Problems

High-frequency problems with pattern tags, approach hints, and complexity — your prioritized study list.

Interview tip For each problem: pattern → brute force → optimized → complexity → edge cases (empty, single, duplicates).

① Arrays & hashing — top problems

ProblemPatternApproach hintComplexity
Two SumHash mapStore complement as you scanO(n) time O(n) space
3SumSort + two pointersFix i, two-pointer rest for zero sumO(n²)
Container With Most WaterTwo pointersMove shorter line inwardO(n)
Longest Substring Without RepeatingSliding windowMap char → last index; shrink on dupO(n)
Product of Array Except SelfPrefix/suffixOutput[i] = left product × right productO(n) O(1)* extra
Merge IntervalsSort + mergeSort by start; merge overlapsO(n log n)
Trapping Rain WaterTwo pointers / stackMax left/right height at each indexO(n)

② Linked lists

ProblemPatternApproach hintComplexity
Reverse Linked ListIn-place reversalprev/curr/next iterationO(n) O(1)
Merge Two Sorted ListsDummy headCompare heads, attach smallerO(n+m)
Linked List CycleFast/slowFloyd detectionO(n) O(1)
Reorder ListMulti-stepFind middle, reverse 2nd half, mergeO(n)
LRU CacheHashMap + DLLGet/put O(1); evict tail on capacityO(1) per op
LRU Cache is a design + DSA favorite — practice implementing from scratch.

③ Trees & graphs

ProblemPatternApproach hintComplexity
Invert Binary TreeDFS/BFSSwap children recursivelyO(n)
Validate BSTDFS boundsPass (min, max) downO(n)
Lowest Common AncestorDFSReturn node if p/q found in subtreesO(n)
Binary Tree Level OrderBFSQueue per levelO(n)
Serialize/Deserialize BTBFS/DFSInclude null markersO(n)
Number of IslandsDFS/BFS gridMark visited; flood fillO(m×n)
Course ScheduleTopo sortKahn or cycle detect DFSO(V+E)
Word LadderBFSBidirectional BFS optionalO(N×L²)

④ Dynamic programming

ProblemPatternState / recurrenceComplexity
Climbing Stairs1D DPdp[i]=dp[i-1]+dp[i-2]O(n) O(1)
House Robber1D DPdp[i]=max(dp[i-1], nums[i]+dp[i-2])O(n)
Coin ChangeUnbounded knapsackdp[a]=min coins for amount aO(amount×coins)
Longest Increasing SubsequenceDP or patienceO(n²) DP or O(n log n) binary search on tails
Word BreakString DPdp[i]=true if prefix breakableO(n²×dict)
Edit Distance2D string DPInsert/delete/replace min opsO(m×n)
Unique PathsGrid DPdp[r][c]=dp[r-1][c]+dp[r][c-1]O(m×n)

⑤ Heaps & design

ProblemPatternKey idea
Kth Largest ElementMin-heap size KOr quickselect O(n) avg
Merge K Sorted ListsMin-heap of headsPop min, push next from that list
Find Median from Data StreamTwo heapsBalance sizes after each add
Top K Frequent ElementsHeap or bucket sortBucket by frequency O(n)
Task SchedulerGreedy + mathCooldown slots or heap simulation

⑥ Binary search classics

ProblemSearch spacePredicate
Search in Rotated Sorted ArrayIndexWhich half is sorted?
Find Minimum in Rotated Sorted ArrayIndexCompare mid with right
Koko Eating BananasSpeed kCan finish in H hours?
Median of Two Sorted ArraysPartition iLeft parts ≤ right parts

⑦ How to practice each problem

  • Read problem — restate in own words
  • Name pattern before coding
  • Brute force first if stuck — then optimize
  • State time and space complexity aloud
  • List edge cases: empty, one element, duplicates, negatives
  • Write clean pseudocode or code in 20–25 min timed
  • Re-solve from memory next day without hints
Quality > quantity: 50 well-understood problems beat 200 shallow solves.

⑧ 2-week prioritized study plan

WeekFocusProblems (daily 2)
Week 1Arrays, hash, two pointersTwo Sum, 3Sum, Container, Longest Substring, Merge Intervals
Week 1Trees BFS/DFSInvert, Validate BST, LCA, Level Order
Week 2Graphs + topoIslands, Course Schedule, Word Ladder
Week 2DP + heapCoin Change, LIS, LRU Cache, Kth Largest

⑨ Complexity quick reference

StructureAccessSearchInsertDelete
ArrayO(1)O(n)O(n)O(n)
Hash mapO(1)*O(1)*O(1)*
Balanced BSTO(log n)O(log n)O(log n)O(log n)
Heapmin/max O(1)O(log n)O(log n)

⑩ Revision checklist

  • Can solve Two Sum, LRU, Islands, Coin Change from memory
  • State pattern and complexity without hesitation
  • Handled follow-ups: 3Sum, follow-up space optimization
  • Practiced timed 25-min sessions
  • Reviewed wrong answers in error log notebook
arraystreesgraphsDPheapinterview