templates

Write it from memory

46 small Java skeletons, one per pattern. Each is compiled and tested. Learn the shape once, and in the interview you only fill in a few lines.

  1. Read the invariant first. It is the one sentence that keeps the code correct.
  2. Close the page and type the template from memory. Then compare, line by line.
  3. For a new problem, rewrite only the fill-in-the-blank lines. The skeleton stays the same.

46 templates

Two pointers, windows & prefix sums

Monotonic stack & deque

Linked lists, sorting & selection

Trees

Heaps & tries

Graph traversal

Shortest paths & spanning trees

Backtracking

Dynamic programming

Bits, range queries & string matching

Java for online assessments