273. Gas Station Circuit
MediumGreedy
Station i gives gas[i] and travelling to the next costs cost[i]. Print the 0-based index of the station from which you can complete the circle, or -1. The answer is unique if it exists.
Input format
Line 1: n Line 2: gas values Line 3: costs
Output format
The start index, or -1.
Example 1
Input
5 1 2 3 4 5 3 4 5 1 2
Output
3
Example 2
Input
3 2 3 4 3 4 3
Output
-1
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…