Problems / Gas Station Circuit
Medium

Gas Station Circuit

Medium 58 submissions 25 coins +100 XP
Array Greedy
Problem Description
Stations sit on a circular road. At station `i` you can fill `gas[i]` units, and driving to station `i + 1` costs `cost[i]`. Starting with an empty tank, return the index of the station from which you can drive all the way around once, or `-1` if impossible. If an answer exists it is unique. **Example 1:** ``` Input: gas = [1, 2, 3, 4, 5], cost = [3, 4, 5, 1, 2] Output: 3 ``` **Example 2:** ``` Input: gas = [2, 3, 4], cost = [3, 4, 3] Output: -1 ``` **Example 3:** ``` Input: gas = [5], cost = [4] Output: 0 ```
Constraints
- `1 <= gas.length == cost.length <= 10^5` - `0 <= gas[i], cost[i] <= 10^4`

Need help?

Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.

Video Call Whiteboard Live Coding Screen Share