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)?
- A. 5
- B. 4
- C. 3
- 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
- Problem: A stack of plates is filled by pushing 1 to 6 in order and popping after each push whenever the top is even. The final stack…
- Problem: A grid of 4×4 cells holds the value r + c (0-indexed). Starting from the top-left corner, what is the maximum total of values…
- Problem: A string is compressed by replacing each maximal run of equal letters with the letter and its count, only when the count is at…
- Problem: Pancake sort uses only prefix reversals on [3, 1, 2]. For each size from n down to 2, bring the largest value of the unsorted…
- Problem: In the array [2, 7, 11, 15, 3, 8], how many pairs i < j have a[i] + a[j] equal to a multiple of 5?
- Problem: The binary search for a value in the sorted array [2, 5, 8, 12, 16, 23, 38, 56, 72, 91] is run with the standard midpoint mid =…