Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

How many permutations of (0, 1, 2, 3) have exactly one position i with p[i] = i?

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

Correct answer: B. 8

Choose the fixed point (4 ways), then count derangements of the other three elements, which is 2. Total 4 times 2 = 8. Counting derangements of all four elements gives a different number.

More Coding Interview Problems questions

Exams that ask this topic