← 返回 roblox 的题目列表Maximum Safe Steps on a Laser Grid
类型:online_judge
Given a numRows × numCols grid whose coordinates are 1-indexed, a robot starts at (curRow, curCol).
There are lasers specified by laserCoordinates. For every laser centered at (r, c):
any robot in row r is destroyed;
any robot in column c is destroyed.
In one step, the robot can move one cell up, down, left, or right. It must stay inside the board and may not enter any row or column covered by a laser.
Return the maximum number of steps the robot can take from (curRow, curCol) while moving continuously in one direction. The starting cell does not count as a step.
Example
numRows = 5, numCols = 6
curRow = 3, curCol = 3
laserCoordinates = [[2, 5], [5, 2]]
Output: 1
Rows 2 and 5, and columns 2 and 5, are unsafe. From (3,3), the robot can move right once to (3,4), but cannot enter column 5. It cannot move upward because row 2 is unsafe.
Constraints
1 ≤ numRows, numCols ≤ 10^9
0 ≤ laserCoordinates.length ≤ 2 × 10^5
Every laser coordinate is within the board.
The starting position is guaranteed to be safe.
Example
Input
5 6 3 3 2
2 5
5 2
Output
1