Problem · Matrix
Adventure to Count Maximum Moves
Learn this problemProblem 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[][]) → intExamples
Example 1
numRows = 8numColumns = 8curRow = 5curColumn = 3laserCoordinates = [[1, 6], [2, 8]]return = 3Moving down visits (6,3), (7,3), and (8,3). The other directions allow at most two safe moves.
Constraints
🌷More Databricks problems
- Find First Anagram IndexPHONE SCREEN · Seen Apr 2026
- Minimize CommuteOA · Seen Apr 2026
- Difference Between Sums of PositionsSeen Sep 2024
- Longest Common Prefix of Number PairsSeen Sep 2024
- Subarray CountingSeen Sep 2024
- Write 'Y' on MatrixSeen Sep 2024
- Binary String RequestsSeen Aug 2024
- Bouncing Diagonal WeightsSeen Aug 2024