Gas Station
Practice this coding question on Coding Gurukul.
Problem statement
An electric shuttle visits charging stops on a circular route. At stop i it receives gas[i] energy and spends cost[i] to reach the next stop. It starts empty and has unlimited capacity. Find the starting index for one complete lap without negative energy. If a valid start exists, it is unique.
Input format
First line: n. Second line: n energy gains. Third line: n travel costs.
Output format
Print the zero-based starting index, or -1 if no complete lap is possible.
Constraints
1 <= n <= 100000; 0 <= gains and costs <= 10000; at most one valid start.
Sample input
3 0 5 0 2 1 2
Sample output
1
Sign in to run or submit a solution in C++, Java or Python.