Data Structures & AlgorithmsHardCodeforces Div2 B · GATE CS

Among all arrangements reachable from [4, 2, 1, 3] by swapping ONE pair of adjacent elements (or by doing nothing), what is the minimum possible number of inversions?

  1. A. 3
  2. B. 4
  3. C. 2
  4. D. 5

Correct answer: A. 3

Swapping adjacent elements a[i] > a[i+1] removes exactly one inversion (the pair itself) and changes no others. Counting adjacent descents gives the number of swappable pairs, which is a different quantity from the total inversion count.

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

Exams that ask this topic