FastPrepFastPrep
Problem Brief

Laser Robot Safe Path

FULLTIMEOA

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.

1Example 1

Input
numRows = 8, numColumns = 8, curRow = 5, curColumn = 3, laserCoordinates = [[1, 6], [2, 8]]
Output
3
Explanation

The 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

Limits and guarantees your solution can rely on.

  • 8 <= numRows <= 20
  • 8 <= numColumns <= 20
  • 1 <= curRow <= numRows
  • 1 <= curColumn <= numColumns
  • 0 <= laserCoordinates.length <= 5
  • laserCoordinates[i].length = 2
  • 1 <= laserCoordinates[i][0] <= numRows
  • 1 <= laserCoordinates[i][1] <= numColumns
  • The robot starts at a different cell from all laser centers.
public int laserRobotSafePath(int numRows, int numColumns, int curRow, int curColumn, int[][] laserCoordinates) {
  // write your code here
}
Input

numRows

8

numColumns

8

curRow

5

curColumn

3

laserCoordinates

[[1, 6], [2, 8]]

Output

3

Sign in to submit your solution.