Robot Return to Origin — Simulation & Parsing

Given a string of single-letter moves on an open grid, decide whether the robot ends the sequence back at its starting point.

Simulation & Parsing · Easy

The problem

A robot starts on an open grid. You get a string of moves: U is one step up, D one step down, L one step left and R one step right. Decide whether the robot ends up where it started after doing every move in order.

The story

A warehouse robot starts at a marked spot on an open floor. Its route is a string of 1 to 12 moves: U steps one square up, D one down, L one left and R one right. After the robot has done every move in order, decide whether it is standing on the spot where it started.

What to return

Constraints

Example

Input
moves = "UD"
Output
true

Solve it

More in Simulation & Parsing

All algorithm problems