Problem-solving techniques

Lessons in this group, roughly in build order:

  • brute-force — Enumerate every candidate solution and test each one — the baseline strategy that is always correct, often…
  • two-pointers — Walk two indices through a sequence — converging from both ends or advancing in tandem — to turn an O(n²)…
  • fast-and-slow-pointers — Two pointers advancing at different speeds — one by 1, one by 2 — so the gap between them encodes cycle…
  • sliding-window — Maintain a contiguous range [left, right] over an array or string, expanding and contracting its ends so…
  • merge-intervals — Sort intervals by start, then sweep once, fusing any that overlap with the interval you are currently…
  • kth-element — Find the k-th smallest/largest item (or the top k) without fully sorting — using a size-k heap for streams…
  • island-matrix-traversal — Treat a 2D grid as an implicit graph — each cell a node, adjacent cells edges — and flood-fill connected…