Classify Final Robot Displacement
Problem statement
A robot starts at vertical position 0 and follows the characters in commands from left to right.
Umoves the robot one step up.Dmoves the robot one step down.
Return \"U\" if the final position is above the start, an empty string if it is at the start, or \"D\" if it is below the start.
Function
classifyVerticalDisplacement(commands: String) → StringExamples
Example 1
commands = "UUDDUDU"return = "U"Four up moves and three down moves leave the robot one step above the start.
Example 2
commands = "UDDU"return = ""Two up moves and two down moves cancel, so the robot returns to its starting position.
Constraints
1 <= commands.length <= 100000commandscontains onlyUandD.