Gas Station Tour Problem
You are presented with a circular track consisting of several petrol pumps. Each petrol pump is indexed from 0 to N-1 and offers certain attributes:
- The quantity of petrol available at the pump.
- The distance to the subsequent petrol pump.
Your objective is to determine the first petrol pump from which a truck, with an empty but unlimited fuel tank, can start its journey and complete the circle or establish that a full circle is not possible.
Note that the truck pauses at every pump, refuels, and consumes 1 litre of petrol per kilometre traveled.
Example:
Input:
3
4
4 6
6 5
7 3
4 5
3
6 4
5 3
8 6
2
2 3
2 2
Output:
1
0
-1
Constraints:
- 1 ≤ T ≤ 50
- 1 ≤ N ≤ 105
- 1 ≤ Amount of petrol on each pump ≤ 109
- 1 ≤ Distance to next pump ≤ 109
Note: You are to implement only the function as the output procedures are handled. Ensure that the indices in your results are 0-based.
The Gas Station Tour Problem involves finding the first petrol pump from which a truck can start its journey and complete a circular track.
Calculate the difference between petrol available and distanc...read more
Top Icertis Associate Software Engineer interview questions & answers
Popular interview questions of Associate Software Engineer
Reviews
Interviews
Salaries
Users/Month