DSA & LeetCode strategy
DSA & LeetCode strategy
why DSA matters
every major tech company tests data structures and algorithms in their interviews. whether it’s FAANG, startups, or mid-size companies, you will be asked to solve coding problems on a whiteboard or in a shared editor.
- the good news: there are only ~15 core patterns that cover 90%+ of interview questions
- the bad news: you can’t cram this in a weekend; it takes consistent practice
- the strategy below gives you a structured path from zero to interview-ready
the strategy: how to actually study
step 1: learn the pattern, not just the problem
every problem below belongs to a pattern category. before solving problems, understand the pattern:
- watch the video solution first to understand the approach
- code it yourself without looking; struggle is where learning happens
- if stuck for 20+ minutes, re-watch the video and try again
- review your solution: can you explain it out loud?
step 2: follow the roadmap in order
the problems below are organized from Foundation to Expert. each level builds on the previous one. don’t skip ahead; the patterns compound.
step 3: track your progress
track which problems you’ve completed and compete with others using the practice link above.
foundation level
these are your building blocks. master these before moving on; nearly every harder problem uses these patterns.
arrays + hashing
foundation for most problems: efficient lookups and storage.
core idea: Use hash maps for O(1) lookups instead of brute-force nested loops. if you’re writing two nested for-loops, there’s almost always a hash map solution.
strategy:
- always ask: “Can I trade space for time with a hash map?”
- for frequency problems, use a counter/dictionary
- for “find pair” problems, store complements in a set
| # | problem | video solution |
|---|---|---|
| 1 | Two Sum | Video |
| 2 | Contains Duplicate | Video |
| 3 | Group Anagrams | Video |
| 4 | Top K Frequent Elements | Video |
| 5 | Product of Array Except Self | Video |
| 6 | Encode and Decode Strings | Video |
| 7 | Longest Consecutive Sequence | Video |
| 8 | Maximum Subarray Sum | Video |
two pointers
builds on arrays to solve search and pairing problems.
core idea: Use two pointers moving toward each other (or in the same direction) to reduce O(n^2) to O(n). works best on sorted arrays.
strategy:
- sort the array first if not already sorted
- left pointer starts at beginning, right at end
- move the pointer that gets you closer to your target
| # | problem | video solution |
|---|---|---|
| 1 | Valid Palindrome | Video |
| 2 | Two Sum II - Input Array Is Sorted | Video |
| 3 | Container With Most Water | Video |
| 4 | 3Sum | Video |
| 5 | Move Zeroes | Video |
| 6 | Remove Duplicates from Sorted Array | Video |
| 7 | Trapping Rain Water | Video |
stack
adds memory of previous elements: great for parsing and monotonic problems.
core idea: Use a stack when you need to remember previous elements and process them in reverse order (LIFO). if you see nested structures or “next greater/smaller” patterns, think stack.
strategy:
- matching brackets/parentheses = stack
- “next greater element” = monotonic stack
- evaluate expressions = stack with operators
| # | problem | video solution |
|---|---|---|
| 1 | Valid Parentheses | Video |
| 2 | Min Stack | Video |
| 3 | Evaluate Reverse Polish Notation | Video |
| 4 | Daily Temperatures | Video |
| 5 | Car Fleet | Video |
| 6 | Largest Rectangle in Histogram | Video |
binary search
builds on arrays for sorted search optimization.
core idea: If the input is sorted (or has a monotonic property), you can eliminate half the search space each step. O(log n) instead of O(n).
strategy:
- classic binary search: find target in sorted array
- “minimum/maximum that satisfies condition” = binary search on answer
- always check: can I binary search the search space?
| # | problem | video solution |
|---|---|---|
| 1 | Search a 2D Matrix | Video |
| 2 | Search in Rotated Sorted Array | Video |
| 3 | Find Minimum in Rotated Sorted Array | Video |
| 4 | Koko Eating Bananas | Video |
| 5 | Median of Two Sorted Arrays | Video |
sliding window
extends array logic for subarray optimization.
core idea: Maintain a “window” over a contiguous subarray/substring. expand the right side, shrink the left side when constraints are violated. turns O(n^2) substring problems into O(n).
strategy:
- “longest/shortest substring with condition” = sliding window
- use a hash map to track window contents
- expand right pointer, shrink left when window is invalid
| # | problem | video solution |
|---|---|---|
| 1 | Longest Substring Without Repeating Characters | Video |
| 2 | Minimum Window Substring | Video |
| 3 | Permutation in String | Video |
| 4 | Longest Repeating Character Replacement | Video |
| 5 | Sliding Window Maximum | Video |
intermediate level
linked & hierarchical structures. these build on your foundation patterns and introduce pointer manipulation and recursion.
linked list
core idea: Pointer manipulation. most linked list problems are about rewiring .next pointers. draw it out on paper first.
strategy:
- use a dummy node to simplify edge cases (empty list, single node)
- fast and slow pointers detect cycles and find midpoints
- reverse a linked list is a building block for many harder problems
| # | problem | video solution |
|---|---|---|
| 1 | Reverse Linked List | Video |
| 2 | Linked List Cycle | Video |
| 3 | Remove Nth Node From End | Video |
| 4 | Reorder List | Video |
| 5 | Add Two Numbers | Video |
trees
core idea: Most tree problems are solved with DFS (recursive) or BFS (level-order with a queue). the recursive structure of trees maps naturally to recursive solutions.
strategy:
- ask: “Can I solve this with a recursive DFS?” - usually yes
- for level-by-level processing, use BFS with a queue
- BST property: left < root < right; use this for validation and search
| # | problem | video solution |
|---|---|---|
| 1 | Invert Binary Tree | Video |
| 2 | Same Tree | Video |
| 3 | Subtree of Another Tree | Video |
| 4 | Lowest Common Ancestor | Video |
| 5 | Binary Tree Level Order Traversal | Video |
| 6 | Validate Binary Search Tree | Video |
| 7 | Kth Smallest Element in a BST | Video |
tries
core idea: A trie (prefix tree) stores strings character by character. perfect for prefix matching, autocomplete, and word search problems.
strategy:
- if the problem involves prefixes or dictionary lookups, think trie
- each node has up to 26 children (for lowercase English)
- mark end-of-word nodes to distinguish complete words from prefixes
| # | problem | video solution |
|---|---|---|
| 1 | Implement Trie (Prefix Tree) | Video |
| 2 | Design Add and Search Words Data Structure | Video |
| 3 | Replace Words | Video |
| 4 | Word Search II | Video |
advanced patterns
recursion & optimization. these patterns are harder but show up frequently in interviews at top companies.
backtracking
core idea: Build solutions incrementally and abandon (“backtrack”) paths that can’t lead to a valid solution. it’s DFS on a decision tree.
strategy:
- draw the decision tree first
- at each step: make a choice, recurse, undo the choice
- prune early: skip branches that violate constraints
| # | problem | video solution |
|---|---|---|
| 1 | Subsets | Video |
| 2 | Combination Sum | Video |
| 3 | Permutations | Video |
| 4 | N-Queens | Video |
| 5 | Sudoku Solver | Video |
heap / priority queue
core idea: Efficiently track the min/max element. use a heap when you need repeated access to the smallest or largest item.
strategy:
- “top K” anything = heap
- use a min heap of size K to find the Kth largest
- use a max heap when you need the largest element quickly
| # | problem | video solution |
|---|---|---|
| 1 | Kth Largest Element in a Stream | Video |
| 2 | Last Stone Weight | Video |
| 3 | Task Scheduler | Video |
| 4 | Top K Frequent Words | Video |
| 5 | Merge K Sorted Lists | Video |
graphs
core idea: Model problems as nodes and edges. most graph problems use BFS (shortest path) or DFS (exploration/connected components).
strategy:
- “number of islands” type = DFS/BFS flood fill
- “shortest path” = BFS (unweighted) or Dijkstra (weighted)
- “can I complete all tasks?” = topological sort (cycle detection)
- always track visited nodes to avoid infinite loops
| # | problem | video solution |
|---|---|---|
| 1 | Number of Islands | Video |
| 2 | Course Schedule | Video |
| 3 | Pacific Atlantic Water Flow | Video |
| 4 | Rotten Oranges | Video |
| 5 | Word Ladder | Video |
dynamic programming (1-D)
core idea: Break a problem into overlapping subproblems. store results to avoid recomputation. if a recursive solution has repeated calls, DP can optimize it.
strategy:
- start with a recursive brute-force solution
- add memoization (top-down) or build a DP table (bottom-up)
- define your state clearly:
dp[i]= what does index i represent? - find the recurrence relation: how does
dp[i]relate to previous values?
| # | problem | video solution |
|---|---|---|
| 1 | Climbing Stairs | Video |
| 2 | Coin Change | Video |
| 3 | Word Break | Video |
| 4 | Partition Equal Subset Sum | Video |
dynamic programming (2-D)
core idea: Same as 1-D DP but with two changing variables. dp[i][j] usually represents a subproblem on a substring, subarray, or grid.
strategy:
- string comparison problems (edit distance, LCS) = 2D DP
- grid traversal problems (unique paths) = 2D DP
- draw out the DP table to visualize transitions
| # | problem | video solution |
|---|---|---|
| 1 | Unique Paths | Video |
| 2 | Longest Common Subsequence | Video |
| 3 | Distinct Subsequences | Video |
| 4 | Edit Distance | Video |
expert level
optimization & logic. these are the patterns that separate good from great in interviews.
intervals
core idea: Sort by start (or end) time, then process intervals linearly. most interval problems become simple after sorting.
strategy:
- sort intervals by start time
- compare current interval’s start with previous interval’s end
- merge, insert, or count based on overlap
| # | problem | video solution |
|---|---|---|
| 1 | Meeting Rooms | Video |
| 2 | Insert Interval | Video |
| 3 | Non-overlapping Intervals | Video |
| 4 | Minimum Number of Arrows to Burst Balloons | Video |
greedy
core idea: Make the locally optimal choice at each step. greedy works when the local optimum leads to the global optimum.
strategy:
- ask: “Does choosing the best option right now hurt future choices?”
- if not, greedy works
- often paired with sorting
| # | problem | video solution |
|---|---|---|
| 1 | Maximum Subarray | Video |
| 2 | Valid Parenthesis String | Video |
| 3 | Gas Station | Video |
| 4 | Hand of Straights | Video |
advanced graphs
core idea: Weighted graph algorithms. Dijkstra for shortest path, Prim’s/Kruskal’s for minimum spanning trees.
strategy:
- “shortest path with weights” = Dijkstra (use a min heap)
- “connect all nodes with minimum cost” = MST (Prim’s or Kruskal’s)
| # | problem | video solution |
|---|---|---|
| 1 | Network Delay Time | Video |
| 2 | Min Cost to Connect All Points | Video |
bit manipulation
core idea: Use binary operations (AND, OR, XOR, shifts) for O(1) space tricks. XOR is especially powerful: a ^ a = 0 and a ^ 0 = a.
strategy:
- “find the single/missing number” = XOR everything
- count bits with
n & (n - 1)to clear lowest set bit - use bit shifts for powers of 2
| # | problem | video solution |
|---|---|---|
| 1 | Single Number | Video |
| 2 | Number of 1 Bits | Video |
| 3 | Counting Bits | Video |
| 4 | Missing Number | Video |
| 5 | Reverse Integer | Video |
math + geometry
core idea: Matrix manipulation, number theory, and spatial reasoning. these problems test your ability to think mathematically.
strategy:
- matrix rotation: transpose + reverse rows
- spiral traversal: track boundaries (top, bottom, left, right)
- for number problems, think about mathematical properties first
| # | problem | video solution |
|---|---|---|
| 1 | Rotate Image | Video |
| 2 | Set Matrix Zeroes | Video |
| 3 | Spiral Matrix | Video |
| 4 | Valid Sudoku | Video |
| 5 | Happy Number | Video |
| 6 | Pow(x, n) | Video |
interview day tips
- clarify (1-2 min): Repeat the problem, ask about edge cases, confirm input/output
- plan (3-5 min): Identify the pattern, explain your approach, discuss time/space complexity
- code (15-20 min): Write clean code, talk through your logic as you go
- test (3-5 min): Walk through an example, check edge cases, fix bugs
common mistakes in interviews
- jumping straight into code without a plan
- going silent when stuck
- not testing your solution with examples
- ignoring edge cases (empty input, single element, duplicates)
- over-engineering when a simple solution works
time complexity cheat sheet
| complexity | name | example |
|---|---|---|
| O(1) | Constant | Hash map lookup |
| O(log n) | Logarithmic | Binary search |
| O(n) | Linear | Single pass through array |
| O(n log n) | Linearithmic | Sorting |
| O(n^2) | Quadratic | Nested loops (usually avoidable) |
| O(2^n) | Exponential | Brute-force subsets |
see also: Winning the interview