Problem · Matrix

Laser Robot Safe Path

Learn this problem
EasyCapital OneFULLTIMEINTERNOA

Problem 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[][]) → int

Examples

Example 1

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

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

  • 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.

More Capital One problems

drafts saved locally
public int laserRobotSafePath(int numRows, int numColumns, int curRow, int curColumn, int[][] laserCoordinates) {
  // write your code here
}
numRows8
numColumns8
curRow5
curColumn3
laserCoordinates[[1, 6], [2, 8]]
expected3
checking account