Back to DSA sheet
Gas Station
MediumGreedyGiven gas and cost at each station on a circular route, return the starting index to complete the circuit, or -1 if impossible.
Constraints
- 1 <= n <= 10^5
- 0 <= gas[i], cost[i] <= 10^4
Sheets
Blind 75Grind 75NeetCode 150NeetCode 250
gas-station.cpp
Loading editor
Custom input (stdin)
Output
Run your code to see its output.