Problem
A circular road has n gas stations, with the numbers 0 to n - 1. Station i gives you gas[i] units of fuel. The drive from station i to the next station uses cost[i] units of fuel.
The next station after station n - 1 is station 0. Your car starts with an empty tank, and the tank has no size limit.
Choose a start station and drive one full circle in the forward direction. Return the index of the start station that lets you complete the circle. If no start station works, return -1.
If a solution exists, only one start station works.
Example 1
- Input:
- gas = [1,6,2,3], cost = [3,2,5,2]
- Output:
- 1
- Explanation:
- Start at station 1 with 6 units. You arrive at station 2 with 4 units, at station 3 with 1 unit, and at station 0 with 2 units. Then you return to station 1 with 0 units.
Example 2
- Input:
- gas = [3,1,2], cost = [2,3,3]
- Output:
- -1
- Explanation:
- The stations give 6 units of fuel in total, but the full circle uses 8 units. No start station works.
Constraints
- n == gas.length == cost.length
- 1 <= n <= 10^5
- 0 <= gas[i], cost[i] <= 10^4
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Advantage Shuffle
Coding · Array · Greedy · Sorting
- Avoid Flood in The City
Coding · Array · Binary Search · Greedy
- Best Time to Buy and Sell Stock II
Coding · Array · Dynamic Programming · Greedy
- Can Place Flowers
Coding · Array · Greedy
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
Bloomberg
Leetcode 134. Gas Station
Reported Mar 23, 2026 · 2 source reports
JUNIOR, SENIOR
Source snapshot: Nov 12, 2026
View sourceExpedia
Leetcode 134. Gas Station
Reported Jun 4, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 4 records
Adobe
Gas Station
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 79.4. This is not an interview probability.
View sourceGoldman Sachs
Gas Station
Reported date not specified · Source window: 6mo