Cyclic Fuel Command Simulation
Reported by candidates from Waymo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Waymo reportedly put this one in front of candidates in September 2026, and the title sounds scarier than it is. Strip the fuel story and it's a plain simulation: walk a command string in a loop, track position and fuel, stop at the first win or the first failure. No graph search, no DP. The grid is up to 200 by 200 and the program is at most 10 characters, so brute force is the whole point. If you blank on the edge cases during the live OA, StealthCoder runs invisibly as a safety net, but you can likely write this yourself in 15 minutes.
The problem
A vehicle starts at S in a rectangular grid. # is blocked, G is a fuel station, and reaching any cell in the final column succeeds. Repeat program cyclically for at most maxSteps. Commands U,D,L,R move one cell and consume one fuel. F adds refillAmount fuel and is valid only while on G. Return the first successful step, 0 if already at the goal, or -1 if a command fails or the bound expires. Function cyclicProgramSteps(grid: String[], program: String, initialFuel: int, refillAmount: int, maxSteps: int) → int Examples Example 1 grid = ["S.."] program = "R" initialFuel = 2 refillAmount = 3 maxSteps = 5 return = 2 Repeating R reaches the final column in two moves. Example 2 grid = ["SG.."] program = "RFR" initialFuel = 1 refillAmount = 2 maxSteps = 6 return = 4 The vehicle moves onto G, refuels, advances once, then the next cycle reaches the last column. Example 3 grid = ["S#.","..."] program = "RDL" initialFuel = 5 refillAmount = 2 maxSteps = 10 return = -1 The first command attempts to enter an obstacle. Constraints 1 <= rows, columns <= 200. 1 <= program.length <= 10 and it contains only UDLRF. 0 <= initialFuel, refillAmount, maxSteps <= 10^6. The grid contains exactly one S.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that there's no trick. Loop step from 1 to maxSteps, pick program[(step-1) % len], and apply it. Check the goal before the loop and return 0 if S is already in the last column. For U, D, L, R: compute the new cell, fail with -1 if it's out of bounds, a '#', or fuel is 0, then decrement fuel. For F: fail if you're not standing on G, otherwise add refillAmount. After every successful command, check whether the column is the last one and return the step number. The pitfalls are order of checks, counting F as a step (Example 2 does), and returning 0 versus 1 off-by-one. Don't try to detect cycles, since maxSteps is capped at 10^6 and the loop is cheap. If the live OA rattles you and you miss one of those rules, StealthCoder is the hedge that catches it in real time.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Cyclic Fuel Command Simulation cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Waymo's OA.
Waymo reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Cyclic Fuel Command Simulation FAQ
What's the trick in Cyclic Fuel Command Simulation?+
There isn't one. It's a direct simulation. Index the program with step modulo its length, apply each command, and return as soon as you hit the last column or a command fails. The work is all in handling the rules in the right order.
Does the F command count as a step?+
Yes. Example 2 shows it: RFR with the G at column 1 returns 4, which only works if F consumes a step. F uses no fuel, it adds refillAmount, and it fails with -1 if you're not on a G cell.
When do I return 0 versus -1?+
Return 0 before any movement if S already sits in the final column. Return -1 if a command fails (wall, bounds, no fuel, F off a station) or if maxSteps runs out without reaching the last column. Otherwise return the step number of the first success.
Do I need cycle detection to stay fast?+
No. maxSteps is at most 10^6 and each step is O(1), so a plain loop is fine. Cycle detection adds bugs, especially since fuel changes the state. Just loop up to maxSteps and stop early on success or failure.
How do I prepare for this in 48 hours?+
Write the simulation once from scratch with the three examples as tests. Focus on failure cases: moving with zero fuel, stepping into a #, leaving the grid, and using F off G. Fuel of 0 with a valid move is the sneaky one to test.