Data Structures & AlgorithmsModerateTCS NQT · Infosys

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

  1. A. 4
  2. B. 10
  3. C. 20
  4. D. 15

Correct answer: B. 10

Every pair of the strictly decreasing array is inverted: C(5,2) = 10. Adjacent pairs give 4, ordered pairs give 20, and C(6,2) = 15 uses the wrong length.

More Coding Interview Problems questions

Exams that ask this topic