Data Structures & AlgorithmsModerateWipro · Capgemini pattern

The array [1, 2, 3, 4, 5, 6] is first rotated RIGHT by 2 positions and then rotated LEFT by 5 positions. What is the result?

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

Correct answer: A. [4, 5, 6, 1, 2, 3]

Rotations compose by adding offsets: right 2 then left 5 = left 3 (mod 6). Left 3 of [1..6] is [4, 5, 6, 1, 2, 3]. Step by step: right 2 → [5, 6, 1, 2, 3, 4]; left 5 → [4, 5, 6, 1, 2, 3].

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

Exams that ask this topic