#K35432. Robot Return to Origin
Robot Return to Origin
Robot Return to Origin
A robot is initially positioned at the origin point (0, 0) on a 2D grid. It receives a sequence of commands represented by characters: 'N' (move north), 'E' (move east), 'S' (move south), and 'W' (move west). Your task is to determine whether the robot returns to its starting position after executing all commands.
The movements can be described by the following formulas:
- $$ x = \text{number of 'E'} - \text{number of 'W'} $$
- $$ y = \text{number of 'N'} - \text{number of 'S'} $$
If both $$ x = 0 $$ and $$ y = 0 $$, then the robot returns to its origin.
inputFormat
The input is given in two lines. The first line contains an integer n representing the number of commands. The second line contains a string of n characters, each being one of 'N', 'E', 'S', or 'W'.
outputFormat
Output a single line containing "YES" if the robot returns to the origin after executing all commands, otherwise output "NO".## sample
6
NESWNE
NO