
You are given a string str consisting only of the characters 'L' and 'R'. Imagine a pivot on a compass that is initially pointing North (N).
Your task is to determine the final direction of the pivot after performing a series of rotations as described by the input string.
A single line containing the string str.
Print a single character representing the final direction: 'N' for North, 'E' for East, 'S' for South, or 'W' for West.
The compass directions follow a cycle: North -> East -> South -> West -> North.
This problem can be efficiently solved by mapping the directions to numbers (e.g., N=0, E=1, S=2, W=3) and using modular arithmetic to track the current state.
LLRLRRL
W
- Initial direction: N
- L: -> W
- L: -> S
- R: -> W
- L: -> S
- R: -> W
- R: -> N
- L: -> W
The final direction is West (W).
R
E
- Initial direction: N
- R: -> E
The final direction is East (E).
The expected time complexity is O(N), where N is the length of the string.
0 <= N <= 10^5
`str` contains only 'L' and 'R'.
Time limit: 1 sec