Data Structures & AlgorithmsVery hardICPC regional · GATE CS

How many permutations p of 1, 2, ..., 6 satisfy p[i] ≤ i + 1 for every position i (1-based)?

  1. A. 17
  2. B. 120
  3. C. 1
  4. D. 64

Correct answer: C. 1

Count from the last position: position i can take any of the values not used by later positions, so the choices multiply as 1, 2, 2, 2, ..., giving 2^(n−1) permutations. The count 2ⁿ overstates it by a factor of two.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic