You have 45 minutes and a whiteboard. Be ready.

← and someone watching every line you write

Practice 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.

Not sure yet? Read Chapter 1 free first →

Build confidence for your next Java coding interview.

117 follow-up questions inside!
48real questions
10chapters
117follow-ups answered
30+code fixes in this edition

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.

  1. Listen and clarifyInput size, nulls, duplicates. Never code on assumptions.
  2. Work an exampleA small, non-trivial case on the board shows the traps.
  3. Say the brute forceA correct slow answer, with its Big O, is your baseline.
  4. OptimizeHash table, two pointers, stack, heap: remove the repeated work.
  5. Write clean codeGood names, small methods, and talk while you write.
  6. 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) ✓

index0123456
s|**|*|*
sum0122334

query (1, 6): sum[5] − sum[0] = 3

free · no sign-up

Get all of Chapter 1 free

Question 1.6 is one of eight in the first chapter. The free sample has the whole chapter: the fundamentals of arrays and strings, then eight interview questions worked with the full method, from clarifying questions and a brute-force solution to the optimal one and its complexity.

Try one on paper before you read the answer. If the method clicks, the other 40 questions are waiting in the book.

Download Chapter 1 free PDF · 41 pages · no email needed

Liked it? Get the full PDF for $15, delivered to your inbox right after payment.

  1. 1.1Reverse a Text
  2. 1.2Validate If a String Has All Unique Characters
  3. 1.3Validate If a String Is a Palindrome
  4. 1.4Compare Application Version Numbers
  5. 1.5Rotate a Matrix by 90 Degrees
  6. 1.6Items in Closed Compartments← above
  7. 1.7DHL Locker Locations
  8. 1.8Largest Sibling of a Number

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

Busy developersAn interview in weeks and a full-time job. You need an efficient review.
Business-software engineersYears of CRUD and integrations; algorithms are rusty.
Juniors and graduatesYour first technical rounds, explained from the ground up.
Seniors on the moveRefresh the fundamentals and nail the follow-up questions.

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

Moises Gamio, author of The Code Interview

Moises Gamio is a software engineer and senior Java developer who has been on the candidate's side of the table at startups and large companies. He wrote down every question, solved it again, and tested it, so you do not have to start from zero. He runs codersite.dev.

Quick answers

Which language are the solutions in?

Java, with JUnit tests. The ideas carry over to any language.

Paperback or PDF?

The paperback is on Amazon. The PDF is the same book as a file you can read and search on any screen, emailed to you right after payment.

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.

your move

Walk in prepared. Walk out with the offer.

Ready for the job after the interview too? Get this book and Software That Can Change as PDFs for $25, $5 less than buying them separately.