Data Structures & AlgorithmsHardICPC regional · CAT · MBA placement

Problem: Place 4 non-attacking rooks on a 4×4 board (no two share a row or column) such that none is on a forbidden cell. Forbidden cells are (0,0), (1,1), (2,2), (3,3), (0,1). How many valid placements exist?

  1. A. 9
  2. B. 24
  3. C. 11
  4. D. 6

Correct answer: D. 6

Placements are permutations σ with σ(i) ≠ i and σ(0) ≠ 1; of the 9 derangements of 4, three send 0 to 1, leaving 6. Ignoring the (0,1) restriction gives the 9 derangements, ignoring all restrictions gives 4! = 24, and 11 merely counts the allowed cells.

More Coding Interview Problems questions

Exams that ask this topic