Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

How many permutations of 1, 2, 3, 4, 5 have exactly 3 inversions (pairs of positions i < j with p[i] > p[j])?

  1. A. 9
  2. B. 20
  3. C. 6
  4. D. 15

Correct answer: D. 15

Use the recurrence for the inversion table: inserting the n-th element into a permutation of n−1 adds between 0 and n−1 inversions, one choice each, so the count obeys the Mahonian numbers. Counting combinations of inversion positions gives a different value.

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

Exams that ask this topic