Description

A robot on a 2D plane starts at the origin (0, 0). Given a sequence of moves (U=up, D=down, L=left, R=right), determine if the robot returns to the origin after completing all moves.

Examples

Input:moves = "UD"
Output:true
Explanation:

Up then down returns to origin.

Input:moves = "LL"
Output:false
Explanation:

Two left moves end at position (-2, 0), not at the origin.

Input:moves = "UDLR"
Output:true
Explanation:

The robot moves up (+1 y), down (-1 y), left (-1 x), then right (+1 x). All movements cancel out: net displacement is (0, 0), so it returns to origin.

Constraints

  • 1 ≤ moves.length ≤ 2 × 10⁴

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!