Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many inversions (pairs i < j with a[i] > a[j]) does the array [3, 1, 4, 1, 5, 9, 2, 6] contain?

  1. A. 9
  2. B. 8
  3. C. 6
  4. D. 11

Correct answer: B. 8

Strict inequality means equal values such as the two 1s do not form an inversion. Merge sort counts inversions in O(n log n) with the same rule.

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

Exams that ask this topic