InterviewLegend

Backtracking

Alex Chen26 min readUpdated 557 real interview reports

Backtracking is the family that shows up the second a Google prompt asks you to produce every arrangement, every selection, or every valid string. It is high-frequency here and easy to fumble, because the code looks small but the state management is where candidates lose the thread. One skeleton covers the group. Once you can write that skeleton from muscle memory, each problem comes down to two decisions: what a "choice" is, and what state distinguishes one branch from the next.

Every problem here builds a partial answer one decision at a time, recurses to extend it, then undoes the last decision before trying the next one. That undo is everything. It lets a single list act as the working answer for the entire search tree, so you are never copying state around. The art is knowing when a branch is hopeless and cutting it early. A search that prunes well runs in a fraction of the time of one that explores every dead end.

What's inside
  • 4 problems, worked step by step
  • about 26 min

Premium lessonGoogle interview guide

These took digging.

What candidates walked out with, from 20,000+ reports, forum threads behind logins and write-ups in Chinese. Then solved step by step.

100 companies. Checked every month.

Unlock all 100 companies

$49 a year · less than $1 a week · 30-day money-back guarantee

Had your Google interview?Tell us what they asked. Reviewed before it goes in, never with your name.
Google interview guide

Know what Google asks before you walk in.

34 coding · 7 system design · 47 behavioral questions

Get Premium$49 a year · 30-day money-back guarantee
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.