Rover Move

Problem Overview

  • Compute the final cell label of a Mars rover moving on an n x n grid from cell 0 using UP, DOWN, LEFT, RIGHT commands.
  • Inputs: int n and String[] cmds; Output: int label defined as row*size + column (size = n).
  • Moves must stay within bounds; no diagonal steps; constraints: 2 <= n <= 20, 1 <= |cmds| <= 20.
  • Real-world setting: rover navigation on a matrix; a coding interview problem and interview question from IBM interviews.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: