Backtracking interview questions

Choose, explore, undo: listing selections and orderings, searching grids and boards, and pruning the search so exponential work stays small in practice.

5 quick facts

– interview-ready · 12 questions in this topic

– of 12 tried

Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.

Questions

  1. Count the picks that hit an exact totalPredict
  2. Every order of a playlistPredict
  3. Every selection from a set of toppingsPredict
  4. Every team of k from n playersFill the blank
  5. Every balanced string of n bracket pairsPredict
  6. Trace a word through a letter gridPick the fix
  7. Cut a word into pieces that each read the same backwardsPredict
  8. Count the ways to place queens that cannot attackPredict
  1. Every distinct order when songs repeatPredict
  2. The backtracking template: choose, explore, undoOrder the steps
  3. Pruning: making exponential searches fast enoughPick the fix
  4. How big is the search space?Predict

Practise this topic

Flashcards · 22

Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.

Quick quiz · 12 questions

One exercise per question, checked as you go. Needs JavaScript.

Mock interview · 2 sets

Timed, out loud, then tick what you covered. Needs JavaScript.

Quick facts

Recall the answer first, then tap Show to check.

Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license