Obstacle-Aware Return to Origin
Problem statement
A robot starts at (0,0). Commands U, D, L, and R move one grid cell. Return true only when the robot never enters any coordinate in obstacles and finishes back at (0,0). The origin is never blocked.
Function
returnsSafely(moves: String, obstacles: int[][]) → booleanExamples
Example 1
moves = "URDL"obstacles = []return = trueThe four moves form a safe loop.
Example 2
moves = "URDL"obstacles = [[-1,1]]return = falseThe robot enters the blocked cell after U then R.
Example 3
moves = "UUDDR"obstacles = []return = falseThe path is safe but finishes one column to the right of the origin.
Constraints
0 <= moves.length <= 10^5and every character is U, D, L, or R.0 <= obstacles.length <= 10^5; obstacle coordinates are unique and exclude the origin.