Code RoomGas station loop
MediumPrep Room Coding #1101

Gas station loop

CodingAlgorithms & data structuresMid–Senior~25 min

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]) → int
Examples
in[[1,2,3,4,5],[3,4,5,1,2]]out3
What 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
InputExpectedGot
[[1,2,3,4,5],[3,4,5,1,2]]3not run yetsample