Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Gas Station

Medium Greedy

There are n gas stations on a circular route. gas[i] is the fuel available at station i and cost[i] is the fuel needed to travel to the next station. Print the index of the station from which you can complete the full circle once, or -1 if impossible. If a solution exists it is unique.

Constraints

1 <= n <= 10^5 0 <= gas[i], cost[i] <= 10^4

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.