Problem · Matrix

Advanture to Count Max Moves

MediumDatabricksINTERNOA

tomtom's note: Feel free to check out source image for the original problem statement :)

Imagine a vast grid-like board, stretching across numRows by numColumns, where a little robot begins its journey. This robot, however, isn’t alone on the board—there are dangerous lasers positioned at specific coordinates, marked by the array laserCoordinates. Each laser is like a sentinel, protecting its row and column by destroying anything that dares to cross its path.

Our brave robot starts its adventure at a particular spot on the board, given by the coordinates (curRow, curColumn). It’s protected from the laser beams in its starting position, but the moment it moves, it’s in danger. The robot can only move in straight lines—either left, right, up, or down—but it must be cautious. The robot’s goal is to explore the board and count the maximum number of cells it can safely move through before any of the laser beams find and destroy it.

Examples
01 · Example 1
numRows = 8
numColumns = 8
curRow = 5
curColumn = 3
laserCoordinates = [[1, 6], [2, 8]]
return = 3
Picture an 8x8 board where a courageous little robot is about to embark on a perilous journey. But danger lurks in the form of two powerful lasers, positioned at the coordinates (1, 6) and (2, 8). These lasers are like sentinels, guarding their rows and columns fiercely, ready to destroy anything that crosses their path.
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
sign in to submit