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 wordsPrint every binary string of length n in lexicographic order (0 before 1).ApplyNot started
  2. 2Target subsetsCount subsets of array positions whose values sum to x. The empty subset is allowed. Equal values at different positions are distinct choices.ConnectNot started
  3. 3Balanced bracket countCount strings containing n opening and n closing parentheses such that every prefix has at least as many openings as closings.ReasonNot started
  4. 4Blocked queensPlace n queens on an n by n board with blocked squares. No two queens may share a row, column or diagonal. Count all placements using only free squares.StretchNot started

Read the lesson