Problems > Returns to the Origin

Returns to the Origin

Difficulty: 1000 2000 ms 128 MB

implementation

Following the same U/D/L/R moves from (0, 0), count how many times the walker is back at the origin after a move.

Input: one line with the move string S.

Output: the number of times the position equals (0, 0) after a move.

Constraints:

  • 1 ≤ |S| ≤ 105

Sample Tests

Input 1
UDLR
Output 1
2
Input 2
UD
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.