Data Structures & AlgorithmsModerateCapgemini · Arrays

The array [1, 2, 3, 4, 5, 6, 7, 8] is rotated left by 3 positions using three reversals: reverse the first 3 elements, reverse the remaining 5, then reverse the whole array. What is the result?

  1. A. [6, 7, 8, 1, 2, 3, 4, 5]
  2. B. [3, 2, 1, 8, 7, 6, 5, 4]
  3. C. [4, 5, 6, 7, 8, 1, 2, 3]
  4. D. [4, 5, 6, 7, 8, 3, 2, 1]

Correct answer: C. [4, 5, 6, 7, 8, 1, 2, 3]

Reversing the parts gives [3,2,1,8,7,6,5,4]; reversing the whole array then yields [4,5,6,7,8,1,2,3].

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

Exams that ask this topic