Robot Final Direction
Problem statement
A robot starts at a point on a horizontal line. Each character in commands moves it one step: L moves left and R moves right.
After processing every command in order, return:
"L"if the robot stops to the left of its starting point.- An empty string if it returns to its starting point.
"R"if it stops to the right of its starting point.
Function
robotFinalDirection(commands: String) → StringExamples
Example 1
commands = "RLLRLL"return = "L"Two right moves and four left moves leave the robot two steps left of its start.
Example 2
commands = "LLRLLLRRRR"return = ""Five left moves and five right moves cancel, returning the robot to its starting point.
Example 3
commands = "RRLR"return = "R"Three right moves and one left move leave the robot two steps right of its start.
Constraints
1 <= commands.length <= 1000- Every character is
LorR.