Problem · Matrix
Laser Robot Safe Path
Learn this problemProblem statement
Imagine a board of size numRows x numColumns with lasers placed on it. Each laser is placed at coordinates [row, column] and destroys every cell in the same row and every cell in the same column.
A robot starts at coordinates (curRow, curColumn). The robot can move in a straight line in exactly one direction: left, right, up, or down. The initial cell is protected and is not destroyed by lasers.
Return the maximum number of cells the robot can safely move through in any one direction before it would enter a destroyed cell or leave the board.
Function
laserRobotSafePath(numRows: int, numColumns: int, curRow: int, curColumn: int, laserCoordinates: int[][]) → intExamples
Example 1
numRows = 8numColumns = 8curRow = 5curColumn = 3laserCoordinates = [[1, 6], [2, 8]]return = 3The lasers destroy rows 1 and 2, and columns 6 and 8. From (5, 3), the longest safe straight path is downward through three cells.
Constraints
8 <= numRows <= 208 <= numColumns <= 201 <= curRow <= numRows1 <= curColumn <= numColumns0 <= laserCoordinates.length <= 5laserCoordinates[i].length = 21 <= laserCoordinates[i][0] <= numRows1 <= laserCoordinates[i][1] <= numColumns- The robot starts at a different cell from all laser centers.
More Capital One problems
- Compare Counts Around PivotOA · Seen Jul 2026
- Format a Newspaper PageOA · Seen Jul 2026
- Match Consecutive Word BoundariesOA · Seen Jul 2026
- Reconstruct Landmark JourneyOA · Seen Jul 2026
- Rightmost Longest Character RunOA · Seen Jul 2026
- Track Received Byte RangesOA · Seen Jul 2026
- Alternate String EndsOA · Seen Jul 2026
- Round-Robin WDL OrderOA · Seen Jul 2026