Data Structures & AlgorithmsVery hardTCS NQT Digital · Product Company SDE

Problem: A list starts as [1, 2, 3, 4, 5, 6, 7, 8]. Four operations are applied in order: rotate the list left by 3; reverse the first 4 elements; rotate right by 2; swap elements at indices 0 and 7. What is the element at index 2 of the final list?

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

Correct answer: C. 7

Rotate left 3 → [4,5,6,7,8,1,2,3]; reverse first 4 → [7,6,5,4,8,1,2,3]; rotate right 2 → [2,3,7,6,5,4,8,1]; swap ends → [1,3,7,6,5,4,8,2], so index 2 holds 7. Rotating in the opposite directions gives 2, and reading 1-based index 2 gives 3 while reading index 3 gives 6.

More Coding Interview Problems questions

Exams that ask this topic