You have 45 minutes and a whiteboard. Be ready.
← and someone watching every line you writePractice Java coding interviews with a repeatable method: clarify the problem, start with brute force, optimize, test edge cases, and explain complexity. Explore 48 worked questions and 117 answered follow-ups in The Code Interview, Second Edition.
Build confidence for your next Java coding interview.
A method you can use in the room
Knowing algorithms is half the job. The book teaches the six steps interviewers look for, then applies them to every problem.
- Listen and clarifyInput size, nulls, duplicates. Never code on assumptions.
- Work an exampleA small, non-trivial case on the board shows the traps.
- Say the brute forceA correct slow answer, with its Big O, is your baseline.
- OptimizeHash table, two pointers, stack, heap: remove the repeated work.
- Write clean codeGood names, small methods, and talk while you write.
- Test and analyzeTrace your example, then the edge cases, then state the complexity.
Look inside question 1.6
Items in closed compartments
Count the items (*) between walls (|) for up to 100,000 range queries. Scanning each range is O(n × m) and times out. The book shows why, then builds three arrays once, so every query is a subtraction.
each query: O(1) instead of O(n) ✓
| index | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| s | | | * | * | | | * | | | * |
| sum | 0 | 1 | 2 | 2 | 3 | 3 | 4 |
query (1, 6): sum[5] − sum[0] = 3
What's on the board
- 1Arrays and Strings8 questions
- 2Lists and Linked Lists4 questions
- 3Math and Logic Puzzles10 questions
- 4Recursion4 questions
- 5Sorting and Searching7 questions
- 6Stacks and Queues3 questions
- 7Hash Table3 questions
- 8Trees2 questions
- 9Graphs3 questions
- 10Coding Challenges4 questions
Who it's for
New in the Second Edition
- Every question now goes from brute force to optimal, with every variable explained.
- Walkthroughs traced step by step, with values checked by running the code.
- 117 follow-up questions, 48 clarifying-question sections, and 48 interview tips.
- More than 30 corrections, including overflow bugs and an infinite loop, fixed and retested.
The author
Quick answers
Which language are the solutions in?
Java, with JUnit tests. The ideas carry over to any language.
How long does it take?
Pick a plan: one weekend for the essentials, two weeks for one chapter a day, or four weeks for everything including the follow-ups.
Is it for beginners or seniors?
New to coding interviews? Start with foundations and step-by-step walkthroughs.
Experienced but rusty? Refresh the patterns, optimization decisions, and follow-up questions.