Gas Station
There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations. Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.

30:00

Gas Station
medium
Topics
Companies

There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations. Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.

Example 1:
Input: {"gas":[1,2,3,4,5],"cost":[3,4,5,1,2]}
Output: 3
Constraints:
  • n==gas.length==cost.lengthn == \text{gas.length} == \text{cost.length}

  • 1n1051 \leq n \leq 10^5

  • 0gas[i],cost[i]1040 \leq \text{gas}[i], \text{cost}[i] \leq 10^4

Input
arr ={"gas":[1,2,3,4,5],"cost":[3,4,5,1,2]}

Start

+1

-3

Net: -2

0

+2

-4

Net: -2

1

+3

-5

Net: -2

2

+4

-1

Net: 3

3

+5

-2

Net: 3

4
Current Tank

0

Total Tank

0

Variables
No variables to display
DepthFunction Call
Stack empty
0/17