Robot On a Grid
A robot is situated in the Cartesian Plane and is currently on \((0,0)\).
It is then given \(N\) instructions (followed sequentially), either to go one unit left (\(L\)), right (\(R\)), up (\(U\)), or down (\(D\)).
Input Specification
The first line will contain the integer \(N\) (\(1 \le N \le 10^5\)), the number of instructions. The second line contains the string of the \(N\) instructions.
Output Specification
Print two space-separated integers: the final coordinates of the robot.
Sample Input
5
LRUDL
Sample Output
-1 0
We can simulate the robot's movements:
\((0,0)\) -> \((-1,0)\) -> \((0,0)\) -> \((0,1)\) -> \((0,0)\) -> \((-1,0)\)
Comments