Problem · Matrix

Adventure to Count Maximum Moves

Learn this problem
MediumDatabricksINTERNOA

Problem statement

You are given a numRows × numColumns board and the 1-based coordinates of several lasers. A laser destroys every cell in its row and every cell in its column.

The robot starts at (curRow, curColumn). Its starting cell is protected, even if it lies in a laser beam. The robot must choose exactly one of the four cardinal directions and then keep moving in a straight line.

Return the maximum number of safe cells the robot can enter before it reaches the board boundary or the next cell would be destroyed by a laser.

Function

solution(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

Moving down visits (6,3), (7,3), and (8,3). The other directions allow at most two safe moves.

Constraints

🌷

More Databricks problems

drafts saved locally
public int solution(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