Dsa
Two Pointers
Hard
Maximize Kilometers
You have a vehicle that can go a certain distance based on a given amount of fuel. You have a list of fueling stations, each with a distance from your current location and an amount of fuel they provide. Your task is to maximize the distance you can travel with a limited initial amount of fuel. Implement a function that reads from standard input and outputs the maximum distance you can reach.
Example:
Input:
3 10
3 8 5
7 5 10
Output:
15
Input Description:
The first line contains two integers n and fuel (1 ≤ n ≤ 10^5, 1 ≤ fuel ≤ 1000). The second line contains n integers indicating the distances of the fueling stations. The third line contains n integers indicating the fuel given at each station, respectively.
Key concepts
two_pointersgreedyoptimization
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