Data Structures & AlgorithmsVery hardGATE CS

An array of 15 elements is rotated right by 6 positions using three in-place reversals (reverse the whole array, then reverse the first 6 elements, then reverse the remaining 9). Counting each swap of two elements as one, how many swaps are performed in total?

  1. A. 16
  2. B. 12
  3. C. 15
  4. D. 14

Correct answer: D. 14

Reversing m elements takes floor(m/2) swaps: 7 + 3 + 4 = 14.

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

Exams that ask this topic