Problem · String
Final Position from Direction Commands
Learn this problemProblem statement
Start at coordinate (0, 0) and process commands from left to right. The letters L, R, U, and D move one unit left, right, up, and down. Lowercase forms have the same meaning. Ignore every other character.
Return [x, y] after all commands.
Function
finalCoordinates(commands: String) → int[]Examples
Example 1
commands = "LRUDx"return = [0,0]The four moves cancel and x is ignored.
Example 2
commands = "RRuLdd?"return = [1,-1]Commands are case-insensitive and ? is ignored.
Constraints
0 <= commands.length <= 1000000commandscontains ASCII characters.