You are given two integer arrays gas and cost, both of length n, representing a set of gas stations arranged in a circular route.
• gas[i] represents how much fuel you can collect at station i.
• cost[i] represents how much fuel it costs to travel from station i to station (i + 1).
You start with an empty fuel tank and can start your journey from any station.
Your goal is to find the starting station index from which you can travel around the entire circuit once in a clockwise direction and return to the same station.
If it’s not possible to complete the full circuit, return -1.
It is guaranteed that if there exists a solution, it will be unique.
Input: gas = [4, 6, 7, 4] cost = [6, 5, 3, 5]
Output: 1
Input: gas = [3, 2, 5, 8, 4] cost = [4, 3, 2, 5, 6]
Output: 2
Accepted:
Submission: