FastPrepLaser Robot Safe Path
Problem · Matrix

Laser Robot Safe Path

Learn this problem
EasyCapital One logoCapital OneFULLTIMEINTERNOA

Problem statement

A special thank-you to the friend who kindly shared that this problem was seen again on August 4, 2026! (∩˃o˂∩)♡

Imagine a board of size numRows x numColumns with lasers placed on it. Their coordinates are given in the two-dimensional array laserCoordinates, where laserCoordinates[i] is a two-element array containing the one-based row and column coordinates of the center of the ith laser.

A laser centered at (row, column) destroys everything in row row and column column. In other words, each laser shoots in all non-diagonal directions until the border of the board.

A robot starts at the one-based coordinates (curRow, curColumn). It can move only in a straight line within the board: left, right, up, or down. Return the maximum number of cells the robot can safely move through in any one direction before being destroyed by a laser.

The initial cell is protected. Lasers cannot destroy the robot there even if that cell is within their destruction area.

A solution with time complexity no worse than O(numRows * numColumns * laserCoordinates.length) will fit within the execution time limit.

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

On the 8 x 8 board, the two lasers are centered at (1, 6) and (2, 8). The longest safe path available to the robot contains 3 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