Study notes

STUDY NOTES · DATA STRUCTURES & ALGORITHMS

The DSA playbook
Fifteen patterns, not a thousand problems.

What an SDE2 coding round expects, the six-step routine for every problem, a cheat sheet that maps problem shapes to patterns, and a four-week plan.

anuragdevon 12th Nov 2026 4 min read Data structures & algorithms · Note 1 of 6

There are thousands of LeetCode problems and roughly fifteen patterns behind them. Recognise the pattern and you’re most of the way to the solution; the rest of the hour is about showing the interviewer how you got there. Everything in this track is in Java, and every snippet is a template you should be able to write from memory.

// THE SHORT VERSION
  • The bar: an optimal solution with few hints, talked through out loud, tested by you before the interviewer asks.
  • The routine: clarify → examples → brute force → optimise → code → test.
  • Input size tells you the target complexity. n ≤ 10⁶ means O(n log n) or better.
  • Practise without AI, timed and out loud. That’s the only practice that transfers.
01

What an SDE2 DSA round expects

SignalSDE1 barSDE2 bar
SolveReaches a working solution, maybe with hintsReaches an optimal or near-optimal solution with few or no hints
CommunicationThinks silently, then codesClarifies, states the brute force, improves it out loud, then codes
Code qualityWorksClean names, helper functions, no copy-paste, handles edge cases
TestingRuns the given exampleDry-runs edge cases on their own (empty input, one element, duplicates, overflow)
ComplexityStates it when askedStates time and space unprompted, and explains the trade-offs
Follow-upsStrugglesHandles “what if the data doesn’t fit in memory / is streaming / is concurrent?”

Typical format: 45 to 60 minutes, 1 or 2 problems, mostly medium, sometimes one medium plus a hard follow-up.

02

The 6-step interview routine

  1. Clarify (2–3 min): input size, ranges, negatives, duplicates, sorted or not, empty input, what to return when no answer exists.
  2. Examples: make up one normal and one edge case.
  3. Brute force: state it and its complexity in one sentence. Don’t code it.
  4. Optimise: find the bottleneck and map it to a pattern (table below). Agree on the approach before coding.
  5. Code: clean, modular, explaining as you go.
  6. Test: dry-run your example and edge cases, fix bugs, then state the final time and space complexity.
03

Pattern recognition cheat sheet

If you see…Think…Note
“Find pair or triplet with sum”, sorted arrayTwo pointersArrays, hashing & windows
Fast lookups, counting, deduplicationHashMap / HashSetArrays, hashing & windows
Longest or shortest contiguous subarray or substring meeting a conditionSliding windowArrays, hashing & windows
Subarray sum equals K, range sumsPrefix sum + HashMapArrays, hashing & windows
Sorted data, or “minimise the maximum” / “smallest X that works”Binary search (on the index or on the answer)Binary search, stacks, heaps & intervals
Next greater or smaller element, histogram problemsMonotonic stackBinary search, stacks, heaps & intervals
Top K, K-th largest, merge K sorted, running medianHeap / priority queueBinary search, stacks, heaps & intervals
Overlapping ranges, meetings, bookingsSort by start + sweepBinary search, stacks, heaps & intervals
Linked list cycle, middle nodeFast and slow pointersLinked lists, trees & graphs
Tree path, depth, subtree propertiesDFS recursion (return info from children)Linked lists, trees & graphs
Level by level, shortest path in an unweighted graphBFSLinked lists, trees & graphs
Dependencies, ordering, “can all courses be finished?”Topological sortLinked lists, trees & graphs
Shortest path with weightsDijkstraLinked lists, trees & graphs
Connectivity, grouping, “are these connected?”Union-FindDesigning data structures
Count ways, min/max cost, “can we reach?” with overlapping subproblemsDynamic programmingDP, backtracking & greedy
All subsets, permutations or combinationsBacktrackingDP, backtracking & greedy
A locally optimal choice is provably globally optimalGreedyDP, backtracking & greedy
Prefix matching, autocompleteTrieDesigning data structures
“Design a data structure with O(1) X and Y”HashMap plus another structureDesigning data structures
04

Input size → target complexity

nTargetTypical approach
≤ 10O(n!)Permutations, backtracking
≤ 20O(2ⁿ)Subsets, bitmask DP
≤ 500O(n³)Triple loop, interval DP
≤ 5,000O(n²)Double loop, 2D DP
≤ 10⁶O(n log n)Sorting, heap, binary search
≤ 10⁸ or moreO(n) / O(log n)Linear scan, math, binary search
05

Java toolbox

JAVA
// Collections you'll use constantly
Map<Integer, Integer> map = new HashMap<>();   map.merge(k, 1, Integer::sum);  map.getOrDefault(k, 0);
Set<Integer> set = new HashSet<>();
Deque<Integer> stack = new ArrayDeque<>();     stack.push(x); stack.pop(); stack.peek();
Deque<Integer> queue = new ArrayDeque<>();     queue.offer(x); queue.poll(); queue.peek();
PriorityQueue<Integer> minHeap = new PriorityQueue<>();
PriorityQueue<Integer> maxHeap = new PriorityQueue<>(Comparator.reverseOrder());
PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> Integer.compare(a[0], b[0])); // never a[0]-b[0] (overflow)
TreeMap<Integer, Integer> tm = new TreeMap<>(); tm.floorKey(x); tm.ceilingKey(x); tm.firstKey();
Arrays.sort(arr); Arrays.fill(dp, -1); Arrays.sort(intervals, (a, b) -> Integer.compare(a[0], b[0]));
StringBuilder sb = new StringBuilder();
int mid = lo + (hi - lo) / 2;                   // avoids overflow
long safe = (long) a * b;                       // overflow-safe product
06

4-week study plan (1.5–2 hrs a day)

WeekFocusGoal
1Arrays, hashing & windows; binary search, stacks, heaps & intervalsWrite every template from memory. 3 or 4 extra problems per pattern on LeetCode
2Linked lists, trees & graphsWrite BFS, DFS, topo sort, Dijkstra and Union-Find without looking
3DP, backtracking & greedyDP: always write the state and transition in English first, then the code
4Designing data structures + mixed timed setsTwo 45-minute mock problems a day, talking out loud, without AI
// WHERE TO PRACTISE NEXT

NeetCode 150, Blind 75 and Grind 75. The notes in this track cover the core of all three.

→

More in Data structures & algorithms

Note 1
The DSA playbook
You're reading this.
Note 2
Arrays, hashing & windows
Note 3
Binary search, stacks, heaps & intervals
Note 4
Linked lists, trees & graphs
Note 5
DP, backtracking & greedy
Note 6
Designing data structures
END OF NOTE 1

Up next: Arrays, hashing & windows

Short, plain-language notes on what interviewers ask an SDE2 and how to think about it.

Contact