You have 45 minutes and a whiteboard. Be ready.

← and someone watching every line you write

48 real Java interview questions, solved step by step the way interviewers expect: clarify, brute force, optimize, test, and defend the Big O.

The final round is not a test of what you know. It is a test of how you think.

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

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.

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?

Both. Each question starts with the simple approach and ends with follow-ups that senior interviews ask.

your move

Walk in prepared. Walk out with the offer.