ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains

The array [1, 2, 3, 4, 5, 6, 7] is shifted left by 2 positions by the procedure below: the element at index k is placed at index (k - 2) mod 7. The procedure then prints the first element of the result. What is printed?

The array [1, 2, 3, 4, 5, 6, 7] is shifted left by 2 positions by the procedure below: the element at index k is placed at index (k - 2) mod 7. The procedure then prints the first element of the result. What is printed?
result[(k - 2) mod n] = a[k] for each k
Print result[0]
  1. A. 6
  2. B. 2
  3. C. 3
  4. D. 1

Correct answer: C. 3

Shifting left by 2 moves the element at index 2 (value 3) to the front. Shifting right moves 6 to the front, reading the last cell gives 2, and the unshifted first element is 1.

More Pseudocode and Code Tracing questions

Exams that ask this topic