Data Structures & AlgorithmsVery hardICPC regional · GATE CS

Problem: A derangement is a permutation with no fixed point. How many derangements of 5 objects exist?

  1. A. 9
  2. B. 76
  3. C. 44
  4. D. 265

Correct answer: C. 44

D(n) = (n − 1)(D(n − 1) + D(n − 2)) gives 1, 2, 9, 44, so D(5) = 44 (also round(5!/e)). D(4) = 9 is an off-by-one, 76 counts the permutations that DO have a fixed point, and D(6) = 265.

More Coding Interview Problems questions

Exams that ask this topic