DSA Study Plan & Complexity

What an SDE2 DSA round actually tests, the Big-O cheat sheet, the 'input size → expected complexity' trick, and a pattern-recognition table to map a problem to a technique fast.

complexitybig-opatternsinterview

What SDE2 DSA actually tests

Not "do you know the trick" — it's: can you recognize the pattern, state the complexity, write clean code, handle edge cases, and communicate while doing it. Talk through the brute force, name the bottleneck, then optimize. A working O(n log n) you can explain beats a buggy O(n) you can't.

Big-O you must recognize on sight

ComplexityNameTypical source
O(1)constanthash lookup, array index
O(log n)logarithmicbinary search, balanced tree, heap push/pop
O(n)linearsingle pass, two pointers
O(n log n)linearithmicsorting, heap-based, divide & conquer
O(n²)quadraticnested loops, naive pair comparison
O(2ⁿ)exponentialsubsets, naive recursion without memo
O(n!)factorialpermutations

The input-size → complexity trick

The constraint tells you the target complexity before you've solved anything:

n up toLikely target
≤ 10–12O(n!) / O(2ⁿ) — backtracking/brute force is fine
≤ 20–25O(2ⁿ) bitmask DP
≤ 500O(n³)
≤ 5,000O(n²)
≤ 10⁶O(n) or O(n log n)
≥ 10⁸O(log n) or O(1)
Use the constraints out loud

"n is up to 10⁵, so an O(n²) ~10¹⁰ won't pass — I need O(n log n) or better." Saying this signals maturity and narrows your options immediately.

Pattern recognition — signal → technique

If you see…Reach for
contiguous subarray/substring, "longest/at most K"Sliding window
sorted array, pair/triplet summing to targetTwo pointers
"search space", "minimum X that works", monotonicBinary search (on answer)
grid/graph, shortest path (unweighted), levelsBFS
connectivity, all paths, cycles, componentsDFS / Union-Find
"number of ways", "min/max cost", overlapping subproblemsDP
top/smallest K, streaming median, merge K listsHeap
all combinations/permutations/subsetsBacktracking
next greater/smaller, matching bracketsMonotonic stack
prefix aggregates, range sumPrefix sums

How to communicate while coding

  1. Restate the problem + ask about edge cases (empty, duplicates, negatives, overflow).
  2. State brute force + its complexity.
  3. Name the bottleneck and the pattern that removes it.
  4. Code, narrating invariants.
  5. Dry-run a small example; then state final time/space.