Skip to Content

DSA Patterns (Codolio Roadmap)

Every problem on the Codolio / Neetcode 150 / Striver A2Z / Blind 75 sheet falls into about 18 recurring patterns. Master the pattern -> recognise it in seconds -> apply the template.

Use the sidebar to jump to any pattern.

The 18 Patterns at a Glance

#PatternWhen you see…Classic problems
1Sliding Windowlongest/shortest subarray with constraintMax Sum Subarray of Size K, Longest Substring w/o Repeats
2Two Pointerssorted array -> find pair / reverseTwo Sum (Sorted), Valid Palindrome
3Fast & Slowlinked list cycle / find middleLinked List Cycle, Middle of LL
4Merge Intervalsoverlapping time-slots / rangesMerge Intervals, Insert Interval
5Cyclic Sortnumbers in [1..N] in O(1) spaceMissing Number, Find Corrupt Pair
6In-place Reversalreverse linked list in chunksReverse LL, Reverse K-Group
7BFSshortest path / level-orderLevel Order, Rotting Oranges
8DFSpath exists / connectivity / topoNumber of Islands, Clone Graph
9Binary Searchsorted array / monotone functionSearch in Rotated Array, Koko Bananas
10Topological Sorttask scheduling dependencyCourse Schedule, Alien Dictionary
11Backtracking”all” combinations / permutationsSubsets, N-Queens, Word Search
12Dynamic Programmingoverlapping subproblemsCoin Change, LCS, Edit Distance
13Greedyactivity selection / interval schedulingJump Game, Gas Station
14Bit ManipulationXOR to find unique / set bitsSingle Number, Counting Bits
15Heap / Priority Queuetop-K / running medianKth Largest, Median from Stream
16Trieprefix search / autocompleteImplement Trie, Word Search II
17Monotonic Stack”next greater element”Daily Temperatures, Largest Rectangle
18Prefix Sumsubarray sum queriesSubarray Sum Equals K, Range Sum

How to Use This Section

  1. Read the What is it? and Data Flow diagrams until you can sketch them on a whiteboard.
  2. Write out the template code (slow, sloppy is fine).
  3. Solve the Classic problems linked in the table.
  4. Time yourself against the Pitfalls — the most common miss is forgetting to update one pointer or shrink the window.

Mnemonic: every pattern has a one-line trigger. Memorise the trigger, not the steps.

Flow: From Pattern Recognition to Solution

+-------------------+      +-------------------+      +-------------------+
|  Read problem     | ---> |  Identify pattern | ---> |  Apply template   |
|  text & examples  |      |  from triggers    |      |  & tweak          |
+-------------------+      +-------------------+      +-------------------+
                                                            |
                                                            v
                                                    +-------------------+
                                                    |  Verify with edge |
                                                    |  cases + dry run  |
                                                    +-------------------+

Universal Interview Heuristic

If you cannot name the pattern within 5 minutes of reading the problem:

  1. Re-read the input/output carefully.
  2. List the constraint keywords (“sorted”, “subarray”, “in-place”, “O(1) space”).
  3. Check the elimination list: any clue pointing to TWO POINTERS, BINARY SEARCH or HASHMAP?
  4. If still stuck, fall back to BRUTE FORCE first (your first 15 minutes) then optimise.
Advertisement