1 How to Use This Book
Reading code feels productive but creates weak recall. The useful unit of study is a closed-book attempt followed by a small correction loop.
1.1 The practice loop
For each problem:
- Read only the prompt and clarification questions.
- Set a 20-minute timer. Talk through a brute-force option, choose an approach, and type it without looking.
- Run three tests: a normal case, a boundary case, and a case aimed at the algorithm’s main failure mode.
- Compare with the book’s solution. Record one sentence about what you missed.
- Delete your code and retype only the difficult part from memory.
Use the worked trace to understand why state changes, not as another artifact to memorize. Before leaving a chapter, be able to say its invariant and complexity without notes.
1.2 If you have only eight hours
The source ranking is by importance, but the best crash plan also maximizes pattern coverage. Use 50-minute focus blocks and 10-minute breaks.
| Time | Work | Outcome |
|---|---|---|
| 0:00–0:30 | Read Interview Playbook and the complexity guide | A repeatable interview process |
| 0:30–1:20 | Two Sum + Group Anagrams | Hash-map lookup and canonical keys |
| 1:30–2:20 | Longest Substring + Valid Parentheses | Sliding window and stack |
| 2:30–3:20 | Binary Search + Rotated Search | Search invariants |
| 3:30–4:20 | Merge Intervals + Three Sum | Sorting, scan, two pointers |
| 4:30–5:20 | Reverse List + Level Order | Pointer mechanics and BFS |
| 5:30–6:20 | Number of Islands + Course Schedule | Components and directed graphs |
| 6:30–7:20 | Maximum Subarray + Coin Change | Greedy-looking DP and table DP |
| 7:20–8:00 | Two timed, closed-book re-solves; review the final checklist | Retrieval under pressure |
If you already know a problem cold, do not reread it. Spend that block on Product Except Self, Validate BST, or your weakest category.
1.3 A longer plan
With several days, attempt four problems per day in rank order, then use a fifth day for random re-solves. Interleave categories: an array problem, a linked-structure problem, a tree/graph problem, and a repeat from yesterday. Spacing and retrieval are more valuable than one long read-through.
1.4 What to memorize—and what not to
Memorize:
- pattern triggers (“sorted” suggests two pointers or binary search);
- invariants (“everything left of
startis outside the window”); - the small API vocabulary for your chosen language (for example, queue and map operations); and
- a small testing checklist.
Do not memorize variable names, comments, or entire programs. Interview prompts vary. You want enough structure to reconstruct the code.
1.5 Using the source files
Sources are grouped under book/src/java, book/src/python, and book/src/rust/src. Each chapter includes those files directly, so the displayed solution and executable tests have one source of truth.
Java class names are descriptive for the book; an interview editor may require public class Solution, so rename the chosen class or begin with java/Solution.java. Python examples are self-contained modules. Rust examples are library modules inside one Cargo package; copy the public function and any required node type into the interview editor. Test helpers in all three languages are examples, not part of the core algorithm.
1.6 Running the examples
All solution code uses standard libraries only. Java tests use the bundled JUnit 4 jars, Python tests use unittest, and Rust tests use the language’s built-in test framework through Cargo.
1.6.1 Java
Every Java file is a complete program containing a solution, JUnit tests, and a main method. The Java runner compiles into book/src/java/.classes; no Maven or Gradle installation is required.
1.6.1.1 Required Java version
Use the Eclipse Temurin JDK 25. The CoderPad configuration targeted by this book reports Java 25.0.1 from Eclipse Adoptium, so using the same major version and distribution locally removes avoidable differences in language features, compiler behavior, and standard-library APIs. Install the newest available Java 25 patch rather than trying to reproduce 25.0.1 exactly: maintenance releases within Java 25 preserve the same language level while supplying fixes.
You need a JDK, not only a JRE, because the runner invokes both javac and java. Verify both commands before running the examples:
java -version
javac -versionBoth versions should begin with 25. The vendor may appear as Eclipse Adoptium or Temurin.
1.6.1.2 Install on macOS with Homebrew
Homebrew provides a versioned Temurin 25 cask. Use temurin@25; the unversioned temurin cask may advance to a later Java release.
brew update
brew install --cask temurin@25Select Java 25 in the current terminal:
export JAVA_HOME="$(/usr/libexec/java_home -v 25)"
export PATH="$JAVA_HOME/bin:$PATH"To make that selection persistent, add those two export lines to ~/.zshrc, then open a new terminal or run source ~/.zshrc. macOS can keep multiple JDKs installed; /usr/libexec/java_home -V lists them.
If which java already points inside ~/.sdkman, use the SDKMAN method below instead of mixing Java managers.
1.6.1.3 Install on Linux with SDKMAN
SDKMAN manages JDKs without requiring a distribution-specific package repository and also works on macOS. Install it if necessary:
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"List the available Java releases and find the newest Temurin identifier beginning with 25 and ending with -tem:
sdk list javaFor example, if the listing contains 25.0.3-tem, install and select it with:
sdk install java 25.0.3-tem
sdk default java 25.0.3-temThe patch number will change over time; substitute the newest available 25.x-tem identifier. sdk current java shows the selected version. When SDKMAN is active, which java normally points to ~/.sdkman/candidates/java/current/bin/java; current is a symlink to the selected JDK.
Eclipse Adoptium also publishes temurin-25-jdk packages for Debian/Ubuntu, Fedora/RHEL, openSUSE, and Alpine. See its official Linux package instructions if system packages are preferable to SDKMAN.
1.6.1.4 Run one program or the complete suite
From the repository root, move into the source directory:
cd book/src/javaRun every Java program:
./run.sh allRun one program by class name or filename:
./run.sh MergeIntervalsSolution
./run.sh MergeIntervalsSolution.javaA successful program ends with JUnit output such as OK (6 tests). If javac -version is not 25 after installation, open a new terminal and inspect which java, which javac, and JAVA_HOME; an older JDK is still earlier on the active path.
1.6.2 Python
Use a current Python 3 interpreter. No virtual environment or package installation is required because the examples depend only on the standard library.
python3 --version
cd book/src/python
./run.sh allRun one module by name or filename:
./run.sh two_sum_solution
./run.sh two_sum_solution.pyThe runner uses python3 -m unittest; a successful suite ends with OK.
1.6.3 Rust
Install a current stable Rust toolchain with Cargo. The package has no third-party dependencies.
rustc --version
cargo --version
cd book/src/rust
cargo testRun the tests for one chapter by filtering on its module name:
cargo test two_sum_solutionThe convenience runner uses the same Cargo commands:
./run.sh all
./run.sh two_sum_solution