Robot Return to Origin Problem

Robot Return to Origin Problem — ExecCode Easy DSA Practice

Solve the Robot Return to Origin problem on ExecCode. Free online easy DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves. Your task is to compute the required answer and return true if the robot returns to the origin after it finishes all of its moves, or false otherwise. There is a robot starting at the position (0, 0), the origin, on a 2D plane. You are given a string moves that represents the move sequence of the robot where moves[i] represents its i^th move. Valid moves are 'R' (right), 'L' (left), 'U' (up), and 'D' (down). Note: The way that the robot is "facing" is irrelevant.

Examples

Input {"moves": "UD"}; Output True. Input {"moves": "LL"}; Output False

Constraints

1 <= moves.length <= 2 * 10^4 moves only contains the characters 'U', 'D', 'L' and 'R'.

Practice Robot Return to Origin free on ExecCode. Browse DSA problems, topic map, and placement guides.