FastPrepMars Rover Robot Controller
Problems/Mars Rover Robot Controller

Mars Rover Robot Controller

Shopify logoShopify● MediumFULLTIMEINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are controlling a rover on an infinite two-dimensional grid. The rover starts at coordinate (x, y) and faces one of four directions: N, E, S, or W.

You are given a command string containing the characters L, R, and M. Command L turns the rover left by 90 degrees, R turns it right by 90 degrees, and M moves it forward one cell in its current direction.

After executing all commands, return the rover's final position and direction in the format "x y D".

Function

getRoverPosition(start: int[], direction: String, commands: String) → String

Examples

Example 1

start = [0, 0]direction = "N"commands = "MRMLM"return = "1 2 N"

The rover moves north to (0, 1), turns east, moves to (1, 1), turns north, and moves to (1, 2).

Example 2

start = [2, 3]direction = "E"commands = "MMRMM"return = "4 1 S"

The rover moves east twice to (4, 3), turns south, then moves south twice to (4, 1).

Constraints

  • start.length == 2
  • direction is one of "N", "E", "S", or "W".
  • commands contains only L, R, and M.
  • The grid is unbounded for this base version.

More Shopify interview questions

  • Deterministic Secret Santa AssignmentPHONE SCREEN · Seen Oct 2026
  • Background Jobs with Exponential BackoffPHONE SCREEN · Seen Jan 2026
  • Word-Guessing Game SessionPHONE SCREEN
  • Card Game: Best First-Player ScoreOA · Seen Nov 2026
  • Macaron Order with Set DiscountsOA · Seen Nov 2026
  • Polynomial CoefficientsOA · Seen Nov 2026
  • Choose Items for a BackpackOA · Seen May 2026
  • Filter Words Containing a LetterOA · Seen Aug 2025
  • Paint HouseOA · Seen Aug 2025
  • Longest Increasing SubsequenceOA · Seen May 2025

Similar questions at other companies

  • Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Recipe Rating ServiceNubank · PHONE SCREEN
  • Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • LRU CacheAthenahealth · PHONE SCREEN
  • Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Mutable Points in a Hash Set and a ListMillennium · PHONE SCREENMillennium interview questions

Interview reports that mention this question

  • Shopify AI Pair Programming Interview: 2 Experiences
  • Shopify Intern Life Story and OA: 20 Experiences (Part 3 of 4)
  • Shopify SWE Intern Interviews: 79 Experiences (Part 1 of 4)

Shopify interview experiences

  • Shopify Intern Older Life Story: 19 Experiences (Part 4 of 4)
  • Shopify Intern OOP Pairing: 20 Experiences (Part 2 of 4)
All Shopify interview questionsSee Shopify hiring insights
Saved
class Solution {
    public String getRoverPosition(int[] start, String direction, String commands) {
      // write your code here
    }
}
Checking account…