Skip to content
  • Dashboard
  • Review
  • Go: plan & chat
  • Roadmap
  • Patterns & lessons49
  • Sheets
  • Problems1.5k
  • Ascend
  • Toolkit
  • Core CS + SQL
  • System Design
  • Machine Coding
  • Interview hub
  • Mock interview
  • Companies & OA
  • Leaderboard
  • Battles
  • College Cup
  • People

Keep your progress

Sync across devices with a free account.

Sign upSign in
Patterns & lessons
Sign inSign up

16 categories · 49 patterns · 90 techniques

Learn a pattern, then revise it.

Every pattern opens to a one-screen cheat sheet and practice sets: what's due, warm-up, interview level, hard and OA, and a lookalike test.

Topic guides

  • Arrays & Two Pointers 5 patternsMost array questions are about not rescanning.
  • Linked Lists 2 patternsLinked-list questions are pointer surgery.
  • Binary Search 2 patternsBinary search halves a search space whose answer flips exactly once.
  • Heaps & Priority Queues 3 patternsA heap hands you the best element so far in O(log n).
  • Backtracking & Recursion 2 patternsBacktracking builds an answer one choice at a time and undoes each choice before trying the next.
  • Trees 4 patternsTree problems are recursion with one question: what does each node return to its parent?
  • Graphs 7 patternsModel the problem as nodes and edges first; the algorithm follows from what you're asked.
  • Dynamic Programming 11 patternsDynamic programming is recursion that remembers: name the state, write the transition, fill the table.
  • Stacks, Queues & Deques 2 patternsA monotonic stack keeps its elements in order by popping everything the new element beats, which answers "next greater" or "previous smaller" for every index in O(n).
  • Strings & Tries 2 patternsStrings bring two patterns of their own.
  • Advanced & Niche 4 patternsLower priority for most product-company interviews, higher for fintech, quant and competitive programming.
Signal → patternread the statement, match the signal: the quick table
Sorted array; find a pair / triplet hitting a target, or shrink from both endsTwo PointersO(n)
Contiguous subarray/substring asked to be longest/shortest/max/min under a constraintSliding WindowO(n)
"Subarray sum equals k" / "divisible by k", or many range-sum queriesPrefix Sum + HashMapO(n)
A linked list that might have a cycle, or you need the middle in one passFast & Slow PointersO(n)
Reverse a list, a sublist, or every k nodes — O(1) extra spaceIn-place LL ReversalO(n)
Intervals / ranges that may overlap: merge, insert, or count rooms/conflictsMerge IntervalsO(n log n)
Array holds n numbers from a 1..n range; find missing / duplicate / first-missing-positiveCyclic SortO(n)
Many range increments, or count overlapping events at a point (bookings, car pool)Difference Array / SweepO(n log n)
Sorted or rotated-sorted array: find target, a boundary (first/last), or a peakBinary SearchO(log n)
"Minimize the maximum" / "maximize the minimum", or answer is testable with a yes/no checkBinary Search on AnswerO(n log R)
"k largest / smallest / most-frequent / closest", or "the kth …"Top-K HeapO(n log k)
Median of a running stream; need max-of-low-half and min-of-high-half togetherTwo HeapsO(log n)/add
k already-sorted lists/arrays to merge, or smallest range covering all kK-way MergeO(N log k)
Generate ALL subsets / combinations / permutationsSubsetsO(2ⁿ)
Build a solution step by step and prune dead ends (board, word search, partition)Backtrackingexp
"Level order", level-by-level, right-side view, zigzag, or minimum depthTree BFSO(n)
Root-to-leaf paths, path sums, or a recursive subtree property (height, diameter)Tree DFSO(n)
It says binary search tree; inorder is sorted; "kth smallest" / "validate"BST LogicO(h)
Rebuild a tree from traversals, or serialize / deserialize itTree ConstructionO(n)
Grid/graph: islands, flood fill, connected regions, clone, unweighted shortest pathGraph BFS / DFSO(V+E)
Prerequisites / dependencies / build order on a DAG; "can you finish?"Topological SortO(V+E)
Connectivity / "number of components" / merge groups / redundant edgeUnion-Find~O(α)
Weighted shortest path, non-negative weights (min time/effort/cost)DijkstraO(E log V)
Shortest path with negative weights, or "cheapest within at most k stops"Bellman-FordO(V·E)
Shortest paths between ALL pairs of nodes (small graph)Floyd-WarshallO(V³)
Connect every node at minimum total costMST (Kruskal/Prim)O(E log V)
Count ways / max value where state depends on the previous one or twoDP · 1D / FibonacciO(n)
Each item is take-or-skip under a capacity; subset hits a target; equal partitionDP · 0/1 KnapsackO(n·W)
Items reusable any number of times: coin change, perfect squares, rod cuttingDP · Unbounded KnapsackO(n·W)
Two strings/arrays compared: edit distance, longest common subsequence, alignDP · LCS familyO(n·m)
Longest increasing / chain subsequence in one ordered arrayDP · LISO(n log n)
Longest palindromic sub-string/-sequence, or fewest palindrome cutsDP · PalindromeO(n²)
2D grid, move right/down: count paths or min/max-cost pathDP · GridO(n·m)
Solve a range [i..j] by trying every split point k (burst balloons, matrix chain)DP · IntervalO(n³)
Buy/sell stock with states — cooldown, fees, or at-most-k transactionsDP · State MachineO(n·k)
Tiny n (≤ ~20) and you must "visit all" / assign everythingDP · BitmaskO(2ⁿ·n)
Count how many numbers in [L, R] satisfy a digit constraintDP · DigitO(digits)
"Next/previous greater or smaller element", histogram area, trapping waterMonotonic StackO(n)
Sliding-window maximum / minimum — running extremum over a window of size kMonotonic DequeO(n)
Prefix matching, autocomplete/dictionary, word search on a grid, maximum XORTrieO(L)
Find a pattern inside a text efficiently, or detect repeated-substring structureString Matching (KMP/Z)O(n+m)
"Single number", XOR tricks, counting set bits, powers of two, subset masksBit ManipulationO(n)
A locally-best choice provably gives the global best: scheduling, jumps, tasksGreedyO(n log n)
"Design a class" with O(1) ops: LRU/LFU, min stack, insert-delete-getRandomDesign / DS comboO(1) ops
Primes (sieve), gcd/lcm, modular arithmetic, fast power, combinatoricsMath / Number Theoryvaries
Range query (sum/min/max) WITH updates, or count smaller elements to the rightSegment Tree / FenwickO(log n)
Pick a random element from a stream of unknown length, one passReservoir SamplingO(n)
TodayReviewPatternsProblems