Data Structures & AlgorithmsModerateProduct placement · Amazon/Microsoft

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

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

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

The net effect is a left rotation by (7 − 5) mod 8 = 2, so the array starts at element 3: [3, 4, 5, 6, 7, 8, 1, 2].

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

Exams that ask this topic