Data Structures & AlgorithmsHardGATE CS · TCS NQT

A road of length 24 has fuel stations at kilometres 3, 7, 9, 14, 17, 22. The car starts at 0 and has range 8 km per tank (it refuels fully at each station). What is the minimum number of stations the car must stop at to reach km 24?

  1. A. 4
  2. B. 3
  3. C. 2
  4. D. 5

Correct answer: B. 3

Greedy: from the current position, go to the farthest station within range. Each jump counts one stop, and the final leg needs no extra refuel since the goal is reachable.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic