call(back)
Algorithms & Data Structuresmedium

Compute Reachable Cells for a Cleaning Robot

A cleaning robot sits in a grid ('.' open, '#' obstacle). When it moves, it picks a direction (up/down/left/right) and slides until it hits a wall or obstacle — it cannot stop mid-slide. It cleans every cell it passes through.

Return [number of cells the robot can clean, number of cells where it can come to rest]. The start cell counts as both cleaned and a rest cell.

. # .        start (0,0): right is blocked; down, then right, then up...
. . .        cleans 5 cells (all but the '#'), can rest at 4

Asked at