Dsa
Binary Search
Warm-up
The Fuel Stop Milestone
An automated rover travels along a straight path. It records its distance from the base at various telemetry milestones. The milestones are sorted in increasing order. Given the rover's current fuel capacity, which allows it to travel a maximum distance D, find the index of the furthest milestone the rover can reach (i.e., the largest index where milestone distance <= D). If it cannot reach even the first milestone, print -1.
Example:
Input:
6 45
10 20 30 40 50 60
Output:
3
Key concepts
binary_searchupper_bound
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now