Practice/Meta/Leetcode 874. Walking Robot Simulation
CodingMust
You are simulating a robot moving on an infinite 2D grid. The robot starts at the origin point (0, 0) facing north (positive Y direction).
The robot receives a sequence of commands:
k means move forward k units in the current direction-1 means turn right 90 degrees-2 means turn left 90 degreesThe grid also contains obstacles at specific coordinates. When executing a forward movement command, the robot moves one unit at a time. If the next step would place the robot on an obstacle, the robot stops moving for that command (but retains its direction) and proceeds to the next command.
Your task is to simulate the robot's movement and return the maximum squared Euclidean distance from the origin that the robot reaches at any point during its journey.
The squared Euclidean distance for a point (x, y) is calculated as x² + y².
Example 1:
` Input: commands = [4, -1, 3], obstacles = [] Output: 25 Explanation:
Example 2:
` Input: commands = [4, -1, 4, -2, 4], obstacles = [[2, 4]] Output: 65 Explanation:
Example 3:
Input: commands = [-1, -1, -2, -2], obstacles = [] Output: 0 Explanation: Robot only turns and never moves from origin.