Data Structures & AlgorithmsHardTCS NQT · Infosys
Problem: On a line of 12 cells (1–12), a robot starts at cell 1. Each second it moves to the cell i+3 if that cell is still ≤ 12 and not yet visited; otherwise to i−1 if that is ≥ 1 and not visited; otherwise it stops. How many seconds does the robot move before it stops?
- A. 7
- B. 5
- C. 6
- D. 11
Correct answer: C. 6
The path is 1 → 4 → 7 → 10 → 9 → 12 → 11, after which 14 is out of range and 10 is visited, so it moves 6 times. Counting cells visited gives 7, stopping on reaching cell 12 gives 5, and trying i − 1 before i + 3 gives 11.
More Coding Interview Problems questions
- Problem: A string is built by writing the first 15 positive integers in binary, concatenated in order (1, 10, 11, 100, ..., 1111). How…
- Problem: A sorted array [1, 3, 3, 5, 8, 8, 8, 13, 21] is searched for the value 8 using the standard lower-bound binary search (find the…
- Problem: A tree has 7 nodes 1–7 with edges 1-2, 1-3, 2-4, 2-5, 3-6, 6-7. Each node is coloured red if its depth from node 1 is even and…
- Problem: Starting with the sorted list 1, 4, 9, 16, 25, 36, two operations alternate: first remove the largest element, then append the…
- Problem: A simple graph has 6 vertices labelled 1–6. Vertex i is adjacent to j exactly when gcd(i, j) = 1 and i ≠ j. How many edges does…
- Problem: What is the number of inversions in the array [6, 2, 8, 1, 9, 4, 3, 7, 5]? (An inversion is a pair of indices i < j with a[i] >…