Check a Robot's Final Displacement

Quick Overview

A robot starts at the origin and follows equal-length moves up, down, left, or right. Determine whether its final displacement is zero after the full sequence; the robot's facing direction does not affect any move.

Check a Robot's Final Displacement

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem A robot begins at (0,0). Each character in moves takes one equal-length step: R right, L left, U up, D down. Directions are absolute and do not depend on facing. Return whether its final position is the origin. ```cpp class Solution { public: bool judgeCircle(string moves); }; ``` ### Examples **Example 1:** ```text moves = "RULD" Output: true Explanation: Horizontal and vertical displacements both cancel. ``` **Example 2:** ```text moves = "UURD" Output: false Explanation: The robot ends one step right and one step up. ``` ### Constraints - There are 1..20000 move characters, all chosen from U,D,L,R. ### Clarifying Questions Use absolute directions and assess the final position rather than an intermediate visit. ```hint Read the boundary condition Which two independent balances determine the final location? ``` ### Contract considerations Use absolute directions and assess the final position rather than an intermediate visit.

Overview: A robot starts at the origin and follows equal-length moves up, down, left, or right. Determine whether its final displacement is zero after the full sequence; the robot's facing direction does not affect any move.

Bloomberg logo
Bloomberg
Jul 3, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

A robot begins at (0,0). Each character in moves takes one equal-length step: R right, L left, U up, D down. Directions are absolute and do not depend on facing. Return whether its final position is the origin.

class Solution {
public:
    bool judgeCircle(string moves);
};

Examples

Example 1:

moves = "RULD"
Output: true
Explanation: Horizontal and vertical displacements both cancel.

Example 2:

moves = "UURD"
Output: false
Explanation: The robot ends one step right and one step up.

Constraints

  • There are 1..20000 move characters, all chosen from U,D,L,R.

Clarifying Questions Guidance

Use absolute directions and assess the final position rather than an intermediate visit.

Contract considerations

Use absolute directions and assess the final position rather than an intermediate visit.