Data Structures & AlgorithmsHardTCS NQT · Infosys
Problem: Starting from 0 on a number line, a frog jumps +4, then −1, then +4, then −1 and so on, alternating, for 25 jumps in total. It stops permanently if it lands on a position that is a multiple of 7 (that landing still counts as a jump). How many jumps are made in total?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
The frog's net drift is +3 per pair of jumps, and the stopping rule ends it at the first multiple of 7. Forgetting that the stopping landing still counts gives one fewer jump.
More Coding Interview Problems questions
- Problem: Count the vertices of the tree with edges 0–1, 0–2, 1–3, 1–4, 2–5, 5–6, 5–7 whose removal leaves every remaining connected…
- Problem: Vertices 1–6 have these directed prerequisites: 1→4, 2→4, 2→5, 3→5, 4→6, 5→6. Among all valid topological orders, the…
- Problem: A graph on vertices 0–7 has edges 0-1, 1-2, 2-0, 3-4, 4-5, 5-6, 6-3, 6-7. The edges are removed one at a time in this order: 2-0…
- Problem: In a graph with vertices 0–6, each edge has weight 0 or 1. Edges: 0-1 (0), 0-2 (1), 1-3 (1), 2-3 (0), 3-4 (1), 4-5 (0), 2-6 (1)…
- Problem: Vertices 0–3 with directed edges 0→1, 0→2, 1→2, 2→0, 1→3, 2→3, 3→3. How many directed walks of exactly length 3 start at vertex 0…
- Problem: A rooted tree has root 1 and children: 1→2 (weight 4), 1→3 (weight 1), 2→4 (weight 2), 2→5 (weight 7), 3→6 (weight 3). The…