DSA & LeetCode strategy

DSA & LeetCode strategy

12 min read · by progsu team · updated May 28, 2026

dsaleetcodetechnical-interviewalgorithms

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:

  1. watch the video solution first to understand the approach
  2. code it yourself without looking; struggle is where learning happens
  3. if stuck for 20+ minutes, re-watch the video and try again
  4. 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
#problemvideo solution
1Two SumVideo
2Contains DuplicateVideo
3Group AnagramsVideo
4Top K Frequent ElementsVideo
5Product of Array Except SelfVideo
6Encode and Decode StringsVideo
7Longest Consecutive SequenceVideo
8Maximum Subarray SumVideo

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
#problemvideo solution
1Valid PalindromeVideo
2Two Sum II - Input Array Is SortedVideo
3Container With Most WaterVideo
43SumVideo
5Move ZeroesVideo
6Remove Duplicates from Sorted ArrayVideo
7Trapping Rain WaterVideo

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
#problemvideo solution
1Valid ParenthesesVideo
2Min StackVideo
3Evaluate Reverse Polish NotationVideo
4Daily TemperaturesVideo
5Car FleetVideo
6Largest Rectangle in HistogramVideo

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?
#problemvideo solution
1Search a 2D MatrixVideo
2Search in Rotated Sorted ArrayVideo
3Find Minimum in Rotated Sorted ArrayVideo
4Koko Eating BananasVideo
5Median of Two Sorted ArraysVideo

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
#problemvideo solution
1Longest Substring Without Repeating CharactersVideo
2Minimum Window SubstringVideo
3Permutation in StringVideo
4Longest Repeating Character ReplacementVideo
5Sliding Window MaximumVideo

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
#problemvideo solution
1Reverse Linked ListVideo
2Linked List CycleVideo
3Remove Nth Node From EndVideo
4Reorder ListVideo
5Add Two NumbersVideo

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
#problemvideo solution
1Invert Binary TreeVideo
2Same TreeVideo
3Subtree of Another TreeVideo
4Lowest Common AncestorVideo
5Binary Tree Level Order TraversalVideo
6Validate Binary Search TreeVideo
7Kth Smallest Element in a BSTVideo

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
#problemvideo solution
1Implement Trie (Prefix Tree)Video
2Design Add and Search Words Data StructureVideo
3Replace WordsVideo
4Word Search IIVideo

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
#problemvideo solution
1SubsetsVideo
2Combination SumVideo
3PermutationsVideo
4N-QueensVideo
5Sudoku SolverVideo

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
#problemvideo solution
1Kth Largest Element in a StreamVideo
2Last Stone WeightVideo
3Task SchedulerVideo
4Top K Frequent WordsVideo
5Merge K Sorted ListsVideo

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
#problemvideo solution
1Number of IslandsVideo
2Course ScheduleVideo
3Pacific Atlantic Water FlowVideo
4Rotten OrangesVideo
5Word LadderVideo

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?
#problemvideo solution
1Climbing StairsVideo
2Coin ChangeVideo
3Word BreakVideo
4Partition Equal Subset SumVideo

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
#problemvideo solution
1Unique PathsVideo
2Longest Common SubsequenceVideo
3Distinct SubsequencesVideo
4Edit DistanceVideo

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
#problemvideo solution
1Meeting RoomsVideo
2Insert IntervalVideo
3Non-overlapping IntervalsVideo
4Minimum Number of Arrows to Burst BalloonsVideo

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
#problemvideo solution
1Maximum SubarrayVideo
2Valid Parenthesis StringVideo
3Gas StationVideo
4Hand of StraightsVideo

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)
#problemvideo solution
1Network Delay TimeVideo
2Min Cost to Connect All PointsVideo

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
#problemvideo solution
1Single NumberVideo
2Number of 1 BitsVideo
3Counting BitsVideo
4Missing NumberVideo
5Reverse IntegerVideo

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
#problemvideo solution
1Rotate ImageVideo
2Set Matrix ZeroesVideo
3Spiral MatrixVideo
4Valid SudokuVideo
5Happy NumberVideo
6Pow(x, n)Video

interview day tips

  1. clarify (1-2 min): Repeat the problem, ask about edge cases, confirm input/output
  2. plan (3-5 min): Identify the pattern, explain your approach, discuss time/space complexity
  3. code (15-20 min): Write clean code, talk through your logic as you go
  4. 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

complexitynameexample
O(1)ConstantHash map lookup
O(log n)LogarithmicBinary search
O(n)LinearSingle pass through array
O(n log n)LinearithmicSorting
O(n^2)QuadraticNested loops (usually avoidable)
O(2^n)ExponentialBrute-force subsets

see also: Winning the interview

last updated

built by progsu ©