Given a array "fuel" where fuel[i] represents how much fuel is available at point i.
And given another array "cost", where cost[i] represents cost it'll take to move to the next point, that is i+1 from i.
You have to determine whether we can complete full circuit from i to i or not.
If yes return the starting point from which it is possible to complete the circuit otherwise return -1.
fuel = [1, 2, 3, 4, 5]
cost = [3, 4, 5, 1, 2]
ans = 3
We can start from index 3, where fuel = 3 and cost = 1
We can observe that for us to complete the circle, sum of fuel must be greater than the cost of the trip.
Based on this idea we can devise a greedy solution.
1. Take end as the first position and start as the last position.
2. From end move towards start until we have fuel left.
3. If at any point fuel left becomes less than zero, decrement the value of start and add the fuel diff to the tank.