PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Shopify

Implement a multi-rover Mars controller

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to implement stateful command parsing, entity management for multiple rovers, and collision-avoidance on an unbounded 2D grid, emphasizing deterministic simulation, input/output specification, and robust handling of invalid operations.

  • easy
  • Shopify
  • Coding & Algorithms
  • Software Engineer

Implement a multi-rover Mars controller

Company: Shopify

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem Build a small command-line “Mars Rover Controller” program. ### Single rover (v1) A rover starts at coordinate **(0, 0)** on an infinite 2D grid and initially faces **North**. The controller must support these commands: - `L`: turn left 90° (N→W→S→E→N) - `R`: turn right 90° (N→E→S→W→N) - `M`: move forward 1 cell in the direction the rover is currently facing After **each** command is processed, the program must report the rover’s **current position and facing direction**. ### Multiple rovers (v2) Extend the controller to manage **multiple rovers** and support: - `CREATE <id>`: create a new rover with the default starting state (0,0,N) - `DELETE <id>`: delete a rover - `SELECT <id>`: make the rover with `<id>` the active rover - Movement/turn commands (`L`, `R`, `M`) apply to the **currently selected** rover Define behavior for invalid operations, e.g. selecting or deleting a non-existent rover, or issuing `L/R/M` with no rover selected. ### Collision avoidance (v3) Add collision prevention: - If the selected rover executes `M` and the **target cell is already occupied by another rover**, the move must **fail** and the rover must remain in its current position/direction. - The program must still report state after the command; you may choose an error/status message format. ## Input / Output You may design the exact CLI format (interactive REPL or reading lines from stdin), but it must be unambiguous and testable. At minimum, specify: - Accepted command syntax - What is printed after each command (position + direction, and optionally status on failures) ## Constraints / Notes - Grid is unbounded; coordinates may be negative. - Rover IDs are unique strings. - Aim for clean, testable design; include unit tests. ## Example (one possible interaction) ``` CREATE a SELECT a M R M CREATE b SELECT b M SELECT a M # fails if b is at the target cell ``` (Your exact printed output format may differ, but it must include position + facing after each command.)

Quick Answer: This question evaluates a candidate's ability to implement stateful command parsing, entity management for multiple rovers, and collision-avoidance on an unbounded 2D grid, emphasizing deterministic simulation, input/output specification, and robust handling of invalid operations.

Related Interview Questions

  • Compute Jaccard Similarity for Lists - Shopify (medium)
  • Implement URL Shortening Codec - Shopify (medium)
  • Simulate a rover fleet - Shopify (medium)
  • Simulate robot moves on a grid - Shopify (medium)
  • Implement a Capacity-Bounded Cache - Shopify (medium)
Shopify logo
Shopify
Dec 23, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
11
0

Problem

Build a small command-line “Mars Rover Controller” program.

Single rover (v1)

A rover starts at coordinate (0, 0) on an infinite 2D grid and initially faces North.

The controller must support these commands:

  • L : turn left 90° (N→W→S→E→N)
  • R : turn right 90° (N→E→S→W→N)
  • M : move forward 1 cell in the direction the rover is currently facing

After each command is processed, the program must report the rover’s current position and facing direction.

Multiple rovers (v2)

Extend the controller to manage multiple rovers and support:

  • CREATE <id> : create a new rover with the default starting state (0,0,N)
  • DELETE <id> : delete a rover
  • SELECT <id> : make the rover with <id> the active rover
  • Movement/turn commands ( L , R , M ) apply to the currently selected rover

Define behavior for invalid operations, e.g. selecting or deleting a non-existent rover, or issuing L/R/M with no rover selected.

Collision avoidance (v3)

Add collision prevention:

  • If the selected rover executes M and the target cell is already occupied by another rover , the move must fail and the rover must remain in its current position/direction.
  • The program must still report state after the command; you may choose an error/status message format.

Input / Output

You may design the exact CLI format (interactive REPL or reading lines from stdin), but it must be unambiguous and testable.

At minimum, specify:

  • Accepted command syntax
  • What is printed after each command (position + direction, and optionally status on failures)

Constraints / Notes

  • Grid is unbounded; coordinates may be negative.
  • Rover IDs are unique strings.
  • Aim for clean, testable design; include unit tests.

Example (one possible interaction)

CREATE a
SELECT a
M
R
M
CREATE b
SELECT b
M
SELECT a
M   # fails if b is at the target cell

(Your exact printed output format may differ, but it must include position + facing after each command.)

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Shopify•More Software Engineer•Shopify Software Engineer•Shopify Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.