Editor

Python recursion and backtracking exercises

Problems that contain smaller copies of themselves, solved with recursion and backtracking and checked by tests.

Beginner

  1. 32. Raise to a PowerRepeated multiplication, built without the shortcut30 XP6 min
  2. 47. Sum of a Nested ListLists inside lists inside lists: what do all the numbers add up to?40 XP8 min

Intermediate

  1. 80. Flatten a Nested DictionarySquash layers of nested settings into a single level70 XP12 min
  2. 86. Tower of HanoiMove a stack of discs, one at a time, never big on small70 XP15 min
  3. 104. All Balanced Bracket StringsEvery well-matched arrangement of a few pairs of brackets85 XP15 min
  4. 274. Phone Keypad WordsWhich words could be hiding behind a phone number?60 XP12 min
  5. 321. Restore the IP AddressesSomebody lost the dots: which addresses could these digits be?75 XP15 min

Advanced

  1. 116. Every Subset, No RepeatsAll the different handfuls you can pick from a bag with look-alikes110 XP18 min
  2. 119. Distinct RearrangementsEvery different order of a list that may hold look-alikes115 XP20 min
  3. 133. Combinations That Hit the TargetAll the ways to reach a total when every number can be reused125 XP22 min
  4. 158. Word SearchCan you trace the word through the letter grid?140 XP25 min
  5. 160. Palindrome PartitionsCut a word into pieces that each read the same both ways145 XP25 min
  6. 389. Matchstick SquareCan these matchsticks be laid out as a perfect square?140 XP30 min
  7. 407. Every Way to Read the MessageThe spaces vanished from a message: every way to read it again150 XP30 min

Expert

  1. 175. N QueensHow many ways can queens share a board without a single attack?200 XP40 min
  2. 193. Sudoku SolverCrack a sudoku puzzle, from tiny boards to the full nine by nine250 XP50 min
  3. 465. Insert the OperatorsPlus, minus or times between the digits: which choices hit the target?240 XP45 min

Other topics

Or see every challenge, with study plans, today's challenge and duels.