A survey rover sits at the origin (0, 0) of an infinite integer grid and executes a string of single-step moves. Each character is one of:
N increases the y-coordinate by 1,S decreases the y-coordinate by 1,E increases the x-coordinate by 1,W decreases the x-coordinate by 1.After executing every move in order, report where the rover ends up.
A single line: a non-empty string of characters, each one of N, S, E, W.
A single line with two integers x y: the rover's final coordinates.
Example 1
Input
NNEE
Expected
2 2
Explanation
Two N moves raise y to 2 and two E moves raise x to 2, so the rover ends at (2, 2).
Example 2
Input
NSNSEW
Expected
0 0
Explanation
The N/S moves cancel to y = 0 and the E/W moves cancel to x = 0, so the rover returns to the origin.
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 →