Returns to the Origin
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
Discussion (opens after you solve — no spoilers before)
No comments yet.