Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

Replace every element simultaneously by (a[i] + a[i-1]) mod 10, indices cyclic, on [1, 2, 3, 4]. What is the resulting array?

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

Correct answer: D. 5 3 5 7

Compute each new value from the original neighbour (the update is simultaneous): position 0 uses a[3] = 4 giving 5, and so on. Updating in place from left to right changes later values.

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

Exams that ask this topic