Trains the technique from
LeetCode 874Walking Robot SimulationThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A floor-sweeping drone sits on its charging pad at cell (0, 0) of a warehouse floor that stretches away without limit in every direction. It begins the sortie facing north, the direction in which y grows.
The drone works through moves in order. Each entry is one of the following:
-2: pivot a quarter turn to its left without leaving the cell it is on;-1: pivot a quarter turn to its right without leaving the cell it is on;k between 1 and 9: creep k cells straight ahead, one cell per step.pillars[i] = [x, y] marks a cell taken up by a roof pillar. Before each single-cell step the drone looks at the cell directly ahead: if a pillar stands there it stays where it is and gives up the rest of that entry, but it still carries out every entry that follows.
Return the largest value of x * x + y * y over every cell the drone occupies during the sortie, where (x, y) is the cell.
Example 1
The drone steps north to (0, 1), finds the pillar ahead and gives up that entry, pivots right to face east, then creeps to (6, 1), where 6 * 6 + 1 * 1 = 37.
Example 2
The drone reaches (0, 5) with nothing in the way, then two left pivots turn it to face south and it comes back to (0, 2); the furthest cell it occupied was (0, 5).
Example 3
Facing west the drone halts at (-2, 0) with the pillar at (-3, 0) ahead of it, then pivots back to north and finishes at (-2, 3), where 4 + 9 = 13.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def sweep_reach(moves: list[int], pillars: list[list[int]]) -> int:public long sweepReach(int[] moves, int[][] pillars)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.