Walking Robot Simulation
A robot on an infinite XY-plane starts at point (0, 0) facing north. The robot receives an array of integers commands, which represents a sequence of moves that it needs to execute. There are only three possible types of instructions the robot can receive:
-2: Turn left90degrees.-1: Turn right90degrees.1 <= k <= 9: Move forwardkunits, one unit at a time.
Some of the grid squares are obstacles. The i^th obstacle is at grid point obstacles[i] = (xi, yi). If the robot runs into an obstacle, it will stay in its current location, on the block adjacent to the obstacle, and move onto the next command.
Return the maximum squared Euclidean distance that the robot reaches at any point in its path. For example, if the distance is 5, return 25.
Note:
- There can be an obstacle at
(0, 0). If this happens, the robot will ignore the obstacle until it has moved off the origin. However, it will be unable to return to(0, 0)due to the obstacle. - North means +Y direction.
- East means +X direction.
- South means -Y direction.
- West means -X direction.
commands = [4,-1,3], obstacles = []25(3, 4), whose squared distance is 3^2 + 4^2 = 25.commands = [4,-1,4,-2,4], obstacles = [[2,4]]65(2, 4) and later reaches (1, 8), whose squared distance is 1^2 + 8^2 = 65.Constraints
- 1 <= commands.length <= 10^4
- commands[i] is either -2, -1, or an integer in the range [1, 9].
- 0 <= obstacles.length <= 10^4
- -3 * 10^4 <= xi, yi <= 3 * 10^4
- The answer is guaranteed to be less than 2^31.