0874. Walking Robot Simulation
https://leetcode.com/problems/walking-robot-simulation
Description
A robot on an infinite XY-plane starts at point (0, 0)
and faces north. The robot can receive one of three possible types of commands
:
-2
: turn left90
degrees,-1
: turn right90
degrees, or1 <= k <= 9
: move forwardk
units.
Some of the grid squares are obstacles
. The ith
obstacle is at grid point obstacles[i] = (xi, yi)
.
If the robot would try to move onto them, the robot stays on the previous grid square instead (but still continues following the rest of the route.)
Return the maximum Euclidean distance that the robot will be from the origin squared (i.e. if the distance is 5
, return 25
).
Note:
North means +Y direction.
East means +X direction.
South means -Y direction.
West means -X direction.
Example 1:
Example 2:
Constraints:
1 <= commands.length <= 104
commands[i]
is one of the values in the list[-2,-1,1,2,3,4,5,6,7,8,9]
.0 <= obstacles.length <= 104
-3 * 104 <= xi, yi <= 3 * 104
The answer is guaranteed to be less than
231
.
ac
Last updated