Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

In [3, 8, 1, 8, 5], you move the rightmost occurrence of the maximum to the last position using adjacent swaps. How many adjacent swaps are needed?

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

Correct answer: B. 1

The rightmost maximum is at index 3, and one adjacent swap moves it past the 5 to the last position.

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

Exams that ask this topic