A rover starts at the origin (0, 0) of an infinite grid, facing North. It executes a command string where each character is:
L: rotate 90 degrees to the left (counter-clockwise) in place,R: rotate 90 degrees to the right (clockwise) in place,F: step one unit forward in the current heading.North increases y, East increases x, South decreases y, West decreases x. Report the final position and heading after all commands.
A single line: a non-empty string of characters, each one of L, R, F.
A single line x y D: the final x, the final y, and the heading letter D (one of N, E, S, W).
Example 1
Input
FFRFF
Expected
2 2 E
Explanation
Two steps North reach (0,2); a right turn faces East; two steps East reach (2,2). Final pose is 2 2 E.
Example 2
Input
LF
Expected
-1 0 W
Explanation
A left turn from North faces West; one forward step reaches (-1,0). Final pose is -1 0 W.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →