Longest Safe Robot Run
MediumSimulation ยท Roblox
A robot starts at the R cell of grid, a list of equal-length strings of . (open), # (obstacle), L (laser) and R, with exactly one R. Each laser fires a beam up, down, left and right that covers every cell it passes until it reaches an obstacle or the edge. Beams pass over lasers and the robot's cell.
The robot picks one direction and moves one cell at a time, entering only open cells that no beam covers. Return the most moves it can make in one direction, or 0 if it cannot move. The starting cell is always safe.
Example 1
- Input:
- grid = ["...L.", ".#.#.", "R....", "....."]
- Output:
- 4
- Explanation
- The beam down column 3 stops at the obstacle in row 1, so row 2 is uncovered and the robot moves right four cells.
Example 2
- Input:
- grid = ["L..R.", ".....", "....."]
- Output:
- 2
Example 3
- Input:
- grid = ["R.L"]
- Output:
- 0
Constraints
1 <= grid.length, grid[i].length <= 100grid[i]contains only.,#,LandRgridcontains exactly oneR