Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

How many inversions does the array [-3, -1, -2] have (pairs i < j with a[i] > a[j])?

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

Correct answer: B. 1

Negation reverses the order of values, so the inversions of [3,1,2] become non-inversions. Negating gives [-3, -1, -2], whose only inversion is the pair (-1, -2).

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

Exams that ask this topic