Problems > Grid Walk

Grid Walk

Difficulty: 900 2000 ms 128 MB

implementation

Starting at (0, 0), follow the moves U (y+1), D (y−1), L (x−1), R (x+1). Print the final coordinates.

Input: one line with the move string S.

Output: two integers: the final x and y.

Constraints:

  • 1 ≤ |S| ≤ 105

Sample Tests

Input 1
URDL
Output 1
0 0
Input 2
UUU
Output 2
0 3

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.