Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: What is the number of inversions in the array [2, 5, 1, 4, 3]?

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

Correct answer: C. 5

Inversions are pairs i < j with a[i] > a[j]: (2,1), (5,1), (5,4), (5,3), (4,3), totalling five.

More Coding Interview Problems questions

Exams that ask this topic