Data Structures & AlgorithmsVery hardGATE CS

How many permutations of {1, 2, …, 8} have exactly two fixed points (positions i with π(i) = i)?

  1. A. 10080
  2. B. 1232
  3. C. 7420
  4. D. 22253

Correct answer: C. 7420

Choose the 2 fixed positions (C(8,2)=28) and arrange the other 6 as a derangement (D6=265): 7420. Using D5 or counting all 6! arrangements ignores that the other six must have no fixed point.

More Coding Interview Problems questions

Exams that ask this topic