Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: On a line of cells 0–9, a token starts at cell 0. Each second it moves right by 2 if the cell is even, and left by 1 if the cell is odd, but never below 0 or above 9 (a blocked move leaves it in place). What is the token's position after 7 seconds?
- A. 9
- B. 8
- C. 14
- D. 10
Correct answer: B. 8
0 → 2 → 4 → 6 → 8 in four seconds; from 8 the move to 10 is blocked, so it stays at 8 for the last three seconds. Clamping to 9 instead of staying gives 9, ignoring the wall gives 14, and treating 10 as a valid cell gives 10.
More Coding Interview Problems questions
- Problem: Count the pairs (i, j) with 1 ≤ i < j ≤ 12 for which the number i·j is a perfect square.
- Problem: The array [4, 9, 2, 7, 5, 6] is processed by insertion sort (standard insertion into the sorted prefix, shifting larger elements…
- Problem: The matrix [[1,2,3],[4,5,6],[7,8,9]] is traversed by rows, but with each row read alternately left-to-right and right-to-left…
- Problem: Find the number of pairs of indices (i, j), i < j, in the array [1, 3, 2, 4, 3, 5] such that a[i] = a[j] + 1 or a[i] = a[j] − 1.
- Problem: A grid has 3 rows and 4 columns. Starting at (0,0), a move goes right or down, and cells with odd row+column are forbidden. How…
- Problem: For the words ["bella", "label", "roller", "dinner", "ladder"], how many pairs (i, j) with i < j are anagrams of each other (same…