PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates competency in grid-based simulation, state updates, boundary condition handling, and sequential command parsing. Commonly asked in Coding & Algorithms interviews to gauge correct implementation and edge-case reasoning, it assesses practical application more than abstract theory and can be extended to path reconstruction or obstacle-aware movement as follow-ups.

  • medium
  • Shopify
  • Coding & Algorithms
  • Machine Learning Engineer

Simulate robot moves on a grid

Company: Shopify

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given an `m x n` grid and a robot that starts at position `(r, c)` (0-indexed). You are also given a string `commands` consisting of characters `'U'`, `'D'`, `'L'`, `'R'`, where each character requests moving the robot one cell up/down/left/right. Rules: - If a move would take the robot outside the grid, ignore that move (the robot stays in place). Return the robot’s final position `(r, c)` after processing all commands. Follow-ups (if time): return the full path; handle blocked cells where moves into obstacles are ignored.

Quick Answer: This question evaluates competency in grid-based simulation, state updates, boundary condition handling, and sequential command parsing. Commonly asked in Coding & Algorithms interviews to gauge correct implementation and edge-case reasoning, it assesses practical application more than abstract theory and can be extended to path reconstruction or obstacle-aware movement as follow-ups.

Return the final robot position after U/D/L/R commands. Moves outside the grid or into optional blocked cells are ignored.

Constraints

  • 0-indexed coordinates
  • blocked is optional

Examples

Input: (3, 3, (1, 1), 'UURDDL')

Expected Output: [2, 1]

Input: (1, 1, (0, 0), 'UDLR')

Expected Output: [0, 0]

Input: (3, 3, (0, 0), 'RRDDLL', [(0, 1)])

Expected Output: [2, 0]

Hints

  1. Check bounds before committing a move.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Grid Robot Command Simulator - Shopify (medium)
  • Compute Theme Similarity - Shopify (medium)
  • Compute Jaccard Similarity for Lists - Shopify (medium)
  • Implement URL Shortening Codec - Shopify (medium)
  • Simulate a rover fleet - Shopify (medium)