Warehouse Robot Moves
A warehouse floor is a grid width columns wide and height rows tall. Cell [x, y] is column x, row y, and [0, 0] is the top-left corner. Some cells hold shelves and are listed in blocked.
A robot starts at start and follows commands, a string of U (y - 1), D (y + 1), L (x - 1) and R (x + 1). A move that would leave the grid or enter a blocked cell is ignored and the robot stays where it is.
Return the final position [x, y].
Example 1
Input: width = 5, height = 5, start = [0,0], commands = "RRDD", blocked = [[2,2]] Output: [2,1] Explanation: R R D D: the second D is blocked by the shelf at [2,2].
Example 2
Input: width = 3, height = 3, start = [1,1], commands = "UUUULLLL", blocked = [] Output: [0,0]
Constraints
- 1 <= width, height <= 1000
- 0 <= commands.length <= 10^5
- start is inside the grid and not blocked
Hint 1
Store blocked cells in a Set of "x,y" strings.
Hint 2
Check the target cell before moving.
Good practice for: Game Developer, Embedded Systems Engineer, Backend Developer, Automation Test Engineer, Full Stack Developer
Run checks your code on 3 sample tests. Submit runs all 8 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.