Problem context and objectives
Mission briefing
Puzzle systems engineer · A game mechanic is behaving incorrectly
Reset after a deficit poisons every earlier start: The Circular Fuel.
Brute force may pass the demo but fail when the world fills with players.
How you win
- 1Recognize when Greedy gas-station reset matches the clues
- 2Keep this true after every move: tank is the surplus from the current candidate start and total is the surplus over every processed station
- 3Reach the result within O(n)
Rules and pressure
- Target cost: O(n)
- State rule: tank is the surplus from the current candidate start and total is the surplus over every processed station
Lesson 1 of 3
Live algorithm trace
Greedy gas-station reset
Complete execution1 of 6
Try station 0 as the first candidate start.
1
start = 0; tank = total = 02
gain = gas[i] - cost[i]3
tank += gain; total += gain4
if tank < 05
start = i + 1; tank = 06
return start if total >= 0 else -1start = 0tank = 0total = 0
Truth to preserve / Cost target
Truth to preserve
tank is the surplus from the current candidate start and total is the surplus over every processed station
Cost target
O(n)
If a candidate start accumulates a negative tank at station i, no station inside that failed segment could reach farther. Reset to i+1 while tracking total surplus to decide global feasibility.
Your call · What should guide every step of this algorithm?