Find the Longest Safe Straight-Line Movement on a Laser Grid

Read the full interview experience this question came from →

Quick Overview

Find a robot's longest safe straight-line movement on a laser-covered grid, where only the initial cell is protected and laser rows and columns are blocked.

Find the Longest Safe Straight-Line Movement on a Laser Grid

Company: Roblox

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Online Assessment

A board has `numRows` rows and `numColumns` columns. A laser at `(row, column)` destroys every cell in its row and every cell in its column. A robot starts at `(curRow, curColumn)`. Its starting cell is protected even if a laser covers that cell. Choose one of four directions—up, down, left, or right—and move in a straight line without turning. The robot may enter a cell only if it is inside the board and is not destroyed. Protection of the starting cell does not protect any destination cell, including the first one. Return the maximum number of cells the robot can safely enter in one direction. Do not count the starting cell. Return `0` if no safe move is possible. ### Input and Output - Inputs: positive board dimensions `numRows` and `numColumns`; a valid starting coordinate `curRow`, `curColumn`; and `laserCoordinates`, a collection of laser coordinate pairs on the board. - Output: one integer, the greatest safe straight-line distance. - Coordinates are one-based: rows are `1` through `numRows`, and columns are `1` through `numColumns`. ### Example ```text numRows = 8 numColumns = 8 curRow = 5 curColumn = 3 laserCoordinates = [[1, 6], [2, 8]] answer = 3 ``` Moving down enters `(6, 3)`, `(7, 3)`, and `(8, 3)` safely, then reaches the board edge. Moving up can enter only `(4, 3)` and `(3, 3)` before row `2`, which is destroyed.

Overview: Find a robot's longest safe straight-line movement on a laser-covered grid, where only the initial cell is protected and laser rows and columns are blocked.

Read the full Roblox Software Engineer interview experience this question came from

|Home/Coding & Algorithms/Roblox
Roblox logo
Roblox
Jul 4, 2026
mediumSoftware EngineerOnline AssessmentCoding & Algorithms
5
0

A board has numRows rows and numColumns columns. A laser at (row, column) destroys every cell in its row and every cell in its column.

A robot starts at (curRow, curColumn). Its starting cell is protected even if a laser covers that cell. Choose one of four directions—up, down, left, or right—and move in a straight line without turning. The robot may enter a cell only if it is inside the board and is not destroyed. Protection of the starting cell does not protect any destination cell, including the first one.

Return the maximum number of cells the robot can safely enter in one direction. Do not count the starting cell. Return 0 if no safe move is possible.

Input and Output

  • Inputs: positive board dimensions numRows and numColumns ; a valid starting coordinate curRow , curColumn ; and laserCoordinates , a collection of laser coordinate pairs on the board.
  • Output: one integer, the greatest safe straight-line distance.
  • Coordinates are one-based: rows are 1 through numRows , and columns are 1 through numColumns .

Example

numRows = 8
numColumns = 8
curRow = 5
curColumn = 3
laserCoordinates = [[1, 6], [2, 8]]
answer = 3

Moving down enters (6, 3), (7, 3), and (8, 3) safely, then reaches the board edge. Moving up can enter only (4, 3) and (3, 3) before row 2, which is destroyed.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...