Data Structures & AlgorithmsModerateTCS NQT · Product Company SDE

Problem: For the array [6, 1, 8, 3, 7], find the minimum number of adjacent swaps needed to sort it in increasing order (adjacent swaps only).

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

Correct answer: C. 4

Each adjacent swap removes exactly one inversion, so the minimum number of adjacent swaps equals the number of inversions in the array.

More Coding Interview Problems questions

Exams that ask this topic