Gas station loop
There are stations arranged in a circle; gas[i] is the fuel available at station i and cost[i] is the fuel needed to drive from station i to the next. Starting with an empty tank at some station, return the starting index from which you can complete the full loop, or -1 if impossible. If a solution exists it is unique. Both lists have equal length and at least one element.
Implement
gas_station(gas: list[int], cost: list[int]) → intExamples
in
[[1,2,3,4,5],[3,4,5,1,2]]out3What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 25 min
solution.py
InputExpectedGot
[[1,2,3,4,5],[3,4,5,1,2]]3not run yetsample