Open In App

Amazon Interview Experience | Set 276 ( On-Campus SDE-I)

  1. Given a circular road having gas stations at varying distances on the road. The cost to move from one station to another is given. You can refuel at each stations with all the present at the station as the tank capacity is infinite. Find if its possible to traverse the complete road and if yes then find the starting position to finish the route.

    Approach: Start from beginning and start traversing the road. If fuel finishes at any point then move the start index backwards and add its gas to the tank. If its still -ve then keep doing it until you have enough to move forward.

 

Article Tags :