FastPrepCyclic Fuel Command Simulation
Problems/Cyclic Fuel Command Simulation

Cyclic Fuel Command Simulation

Waymo logoWaymo● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes a car with obstacles, fuel stations, a 100-unit initial tank, 50-unit refills, and at most ten repeating commands. The exercise here evaluates a candidate repeating program under an explicit step bound rather than synthesizing one; match is about 76%.

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 = 2refillAmount = 3maxSteps = 5return = 2

Repeating R reaches the final column in two moves.

Example 2

grid = ["SG.."]program = "RFR"initialFuel = 1refillAmount = 2maxSteps = 6return = 4

The vehicle moves onto G, refuels, advances once, then the next cycle reaches the last column.

Example 3

grid = ["S#.","..."]program = "RDL"initialFuel = 5refillAmount = 2maxSteps = 10return = -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.

More Waymo problems

  • Fixed-Order Task Run Time With CooldownPHONE SCREEN · Seen Oct 2026
  • Reorderable Task Scheduler With CooldownPHONE SCREEN · Seen Oct 2026
  • Island Area and Water BoundaryPHONE SCREEN · Seen Sep 2026
All Waymo interview questionsSee Waymo hiring insights
Saved
class Solution {
    public int cyclicProgramSteps(String[] grid, String program, int initialFuel, int refillAmount, int maxSteps) {
        // Write your solution here.
    }
}
Checking account…