Data structures & algorithms
Learn the pattern first, trace a small example, then try an original practice question. Work through the topics in order or jump to one you want to strengthen.
Your learning path
Each lesson starts with the idea, then gives you a question to try.
Sliding Window
Move a contiguous range through an array or string while maintaining only the information the current range needs.
Two Pointers
Use two positions to narrow a search, compare ends, or compact data in one pass.
Fast/Slow Pointers (Linked List)
Move two linked-list references at different speeds to detect cycles or locate a middle position.
Binary Search on Sorted Data
Discard half the remaining sorted search space after each comparison.
Binary Search on Answer
Search the answer range when feasibility changes monotonically as the candidate answer changes.
Hashing / Frequency Maps
Use a set or map to track what has appeared and how often, usually with constant-time average lookup.
Prefix Sum / Running Sum
Precompute cumulative totals so range sums and counting conditions can be answered efficiently.
Difference Array / Range Updates
Apply many interval increments cheaply, then reconstruct the final values with a running sum.
Monotonic Stack
Keep a stack in increasing or decreasing order to find the next greater or smaller item efficiently.
Monotonic Queue / Deque
Maintain only useful candidates in a deque to answer moving-window minimum or maximum queries.
Heap / Top K
Use a heap to repeatedly access the smallest or largest candidate without fully sorting everything.
Intervals
Sort and reason about ranges to merge overlaps, find conflicts, or select non-overlapping intervals.
Greedy Scheduling / Sorting
Sort by a useful criterion and make locally optimal choices when an exchange argument supports them.
Linked List Manipulation
Rewire node references carefully to reverse, merge, split, or transform lists in place.
Tree DFS
Explore a tree recursively or with a stack, combining information from child subtrees.
Tree BFS / Level Order
Use a queue to visit tree nodes in layers, from the root outward.
BST Problems
Use the binary search tree ordering invariant to search, validate, and select values efficiently.
Backtracking Basics
Build candidate solutions step by step and undo each choice when exploring another branch.
Backtracking with Constraints
Prune partial choices as soon as they cannot lead to a valid complete solution.
Graph BFS / DFS
Traverse connected vertices while recording which nodes have already been visited.
Topological Sort / DAG
Order directed acyclic graph nodes so every prerequisite appears before the work that depends on it.
Union Find / DSU
Track disjoint connected groups with near-constant amortized merge and find operations.
Shortest Path
Choose a graph algorithm that matches edge weights and the path objective.
MST / Graph Greedy
Connect every vertex with minimum total edge weight while avoiding cycles.
Trie
Store words by shared prefixes to support efficient prefix search and dictionary lookup.
Bit Manipulation
Use binary representations and bitwise operations to solve compact state and parity problems.
1D DP Basics
Reuse answers to smaller prefixes or states instead of recomputing the same subproblems.
Knapsack / Subset DP
Track which capacities, sums, or resource combinations are reachable as items are considered.
Grid DP
Compute paths or costs in a grid by combining answers from neighboring cells.
String DP / Sequence DP
Use a table of prefix states to compare sequences, edit strings, or count subsequence relationships.