Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The array [1, 2, 3, 4, 5, 6, 7] is rotated right by 3 positions (the last 3 elements move to the front). What is the element at index 0 after the rotation?

  1. A. 6
  2. B. 4
  3. C. 7
  4. D. 5

Correct answer: D. 5

A right rotation by k moves the last k elements to the front, so index 0 takes the element at index n−k. Rotating left by k gives a different first element.

More Coding Interview Problems questions

Exams that ask this topic