#K40237. Robot Return to Origin
Robot Return to Origin
Robot Return to Origin
A robot starts at the origin (0, 0) on a 2D plane. It is given a sequence of moves represented by the characters N
(north), S
(south), E
(east), and W
(west). The robot's final position \((x, y)\) is computed by:
\(x = \text{\#E} - \text{\#W}, \quad y = \text{\#N} - \text{\#S}\)
The robot returns to its starting position if and only if \(x = 0\) and \(y = 0\). Your task is to determine whether the robot returns to the origin after executing all the given instructions.
inputFormat
The input consists of a single line containing a non-empty string of movement instructions. Each character in the string is one of N
, S
, E
, or W
.
Example: ENWS
outputFormat
Output a single line: YES
if the robot returns to the origin, or NO
otherwise.
ENWS
YES