Notice Period

Fuel Loop

medium

A delivery scooter must complete one full lap of a circular route with n fuel stops. Stop i dispenses fuel[i] liters, and riding from stop i to the next stop burns cost[i] liters. The tank starts empty and has no size limit.

Return the index of the unique starting stop from which the scooter can complete the entire lap, or -1 if no stop works. If an answer exists it is guaranteed to be unique.

Example 1
in fuel = [1, 2, 3, 4, 5], cost = [3, 4, 5, 1, 2]
out 3
Start at stop 3 with 4 liters: tank never dips below zero around the loop.
Example 2
in fuel = [2, 3, 4], cost = [3, 4, 3]
out -1
Total fuel (9) is less than total cost (10) — no start can work.
Constraints
  • · 1 <= n <= 10^4
  • · 0 <= fuel[i], cost[i] <= 10^4
  • · len(fuel) == len(cost)
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.