Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: A deque holds 1, 2, 3, 4, 5 from left to right. The operation rotate(2) moves the last 2 elements to the front (rotate right by 2). After it, what is the element at index 1?

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

Correct answer: A. 5

deque.rotate(n) with positive n moves elements from the right end to the left, so the deque becomes 4, 5, 1, 2, 3. Rotating left instead gives a different index-1 element.

More Coding Interview Problems questions

Exams that ask this topic