Gas Stations
Try to solve the Gas Stations problem.
We'll cover the following
Statement
There are gas stations along a circular route, where the amount of gas at the station is gas[i]
.
We have a car with an unlimited gas tank, and it costs cost[i]
 of gas to travel from the station to the next station. We begin the journey with an empty tank at one of the gas stations.
Find the index of the gas station in the integer array gas
such that if we start from that index we may return to the same index by traversing through all the elements, collecting gas[i]
and consuming cost[i]
.
-
If it is not possible, return -1.
-
If there exists such index, it is guaranteed to be unique.
Constraints:
gas.length
cost.length
- 1
gas.length
,cost.length
- 0
gas[i]
,cost[i]
Create a free account to view this lesson.
Continue your learning journey with a 14-day free trial.
By signing up, you agree to Educative's Terms of Service and Privacy Policy