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?

  1. A. 4
  2. B. 3
  3. C. 2
  4. 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

Exams that ask this topic