Skip to content
Back to libraryPart 2 · Core techniques

2.4Recursion and backtracking

Before you start

It helps to have read 1.3 Arrays and strings and 1.2 Complexity and limits. Overall level: Core.

Practice: Recursion and backtracking

0 of 4 solved

About these problems

Apply, Connect, Reason and Stretch describe difficulty within this topic, not an official contest rating. Open any problem in any order; reading the chapter first is optional.

  1. 1Binary wordsA binary string uses only the characters 0 and 1. Print every binary string of length n in lexicographic (dictionary) order, where 0 comes before 1.ApplyNot started
  2. 2Target subsetsYou are given a target x and a list of n integers a1, a2, ..., an. Count the subsets of positions whose chosen values sum to x. The empty subset, with sum 0, is allowed. Equal values at different positions count as different choices.ConnectNot started
  3. 3Balanced bracket countCount the strings made of n opening parentheses ( and n closing parentheses ) such that, reading from left to right, every prefix has at least as many opening as closing parentheses.ReasonNot started
  4. 4Blocked queensA board has n rows and n columns, and some squares are blocked. Count the ways to place n queens on free squares so that no two queens share a row, a column or a diagonal.StretchNot started

Read the lesson