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])?
- A. 9
- B. 20
- C. 6
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the minimum number of positive perfect cubes (1, 8, 27, ...) whose sum is exactly 31? Repeats are allowed.
- How many substrings of "abacaxayaba" are palindromes of ODD length at least 3?
- Among all distinct permutations of the letters of "dbca" sorted alphabetically, what is the 1-based position of "dbca" itself?
- List all distinct permutations of the multiset of letters in "aabc" in alphabetical order. What is the 5th string in this list?
- What is the length of the longest substring of "aabbcabccbba" in which every letter occurs an EVEN number of times (0 counts as even)?
- How many unordered pairs of positions in [2, 8, 9, 18, 4, 6, 12] have a product that is a perfect square?