First Return to Origin

JavaScript Medium 3 views
Back to Questions

Problem Description

You get command string L,R,U,D. Find the earliest step (1-based) when position becomes (0,0) again. If never, print -1.

Input Format

One line command string.

Output Format

One integer step or -1.

Sample Test Case

Input:
LLRRUD
Output:
4

Constraints

Length up to 2e5.

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next