Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: The circular array [3, 1, 4, 2] has a 'next' pointer from each index i to (i+1) mod 4. Starting at index 0 and jumping by the value at the current index, how many distinct indices are visited before the first repeat (including index 0)?

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

Correct answer: B. 4

Follow the jump sequence and stop at the first revisit; the visited list is the answer. Counting jumps instead of distinct indices gives one more than the visited count when the cycle closes.

More Coding Interview Problems questions

Exams that ask this topic