A robot starts at the origin, position (0, 0), on a 2D Cartesian plane. You are given a string of moves representing a sequence of its movements.
The valid moves are:
'U' (Up): The robot's y-coordinate increases by 1.
'D' (Down): The robot's y-coordinate decreases by 1.
'R' (Right): The robot's x-coordinate increases by 1.
'L' (Left): The robot's x-coordinate decreases by 1.
Your task is to determine if the robot ends up back at the origin (0, 0) after completing all the moves in the sequence.
Input Format:
The first and only line of input contains a single string moves.
Output Format:
Your function should return a boolean value: true if the robot returns to the origin, and false otherwise.
Note:
The problem can be solved by simulating the robot's position. Alternatively, a more direct approach is to realize that the robot returns to the origin if and only if the total number of 'U' moves equals the total number of 'D' moves, AND the total number of 'L' moves equals the total number of 'R' moves.