Coding Interview Patterns
Learn the pattern, not the problem.
Go for Interviews
The Go you need for coding interviews: slices, maps, heaps, runes and common gotchas.
Big-O Cheat Sheet
Estimate time and space cost, and know what complexity the input size demands.
Recursion Basics
Solve a problem with a smaller copy of itself: base case, call stack and why recursion can repeat work.
Arrays & Hash Map
Trade memory for speed: look things up in O(1) instead of scanning again.
Two Pointers
Walk two indexes through sorted or symmetric data instead of nesting loops.
Sliding Window
Keep a moving range valid and update it incrementally instead of recomputing.
Prefix Sum
Precompute running totals so any range sum is a subtraction.
Stack Basics
Last in, first out: matching pairs, evaluating expressions, undo and a running minimum.
Stack / Monotonic Stack
Use a stack to remember unresolved items; keep it ordered to find next greater/smaller.
Binary Search
Halve the search space whenever a yes/no condition is monotonic.
Linked List · Fast & Slow Pointers
Rewire pointers carefully; use a fast and slow pointer to find cycles and middles.
Intervals
Sort by start, then sweep and merge overlapping ranges.
Trees: BFS / DFS
Recurse on subtrees, or sweep level by level with a queue.
Heap / Top-K
Keep only the best K items; the heap tells you the worst of them in O(log k).
Graphs: BFS / DFS / Topological Sort
Model relationships as nodes and edges; traverse with a visited set.
Backtracking
Build answers one choice at a time; undo the choice and try the next.
Dynamic Programming
Break a problem into overlapping subproblems and solve each only once.
2-D Dynamic Programming
Grids, two strings and ranges: when a subproblem needs two numbers, fill a table cell by cell.
Greedy
Take the best local choice and never undo it, when you can argue it is safe.
Union-Find
Track which items are in the same group and merge groups in near-constant time.
Advanced Graphs · Dijkstra & Spanning Trees
Weighted graphs: cheapest paths with a heap, cheapest ways to connect everything, and ordering by rules.
Tries
Store words letter by letter so any prefix question is a short walk down a tree.
Bit Manipulation & Math
XOR tricks, bit counting, in-place matrix moves, fast exponentiation and digit-by-digit arithmetic.