Rover Move
A Mars rover is directed to move within a square matrix. It accepts a sequence of commands to move in any of the four directions from each cell: [UP, DOWN, LEFT or RIGHT]. The rover starts from cell 0. and may not move diagonally or outside of the boundary.
Each cell in the matrix has a position equal to:
(row * size) + column
where row and column are zero-indexed, size = row length of the matrix.
Return the final position of the rover after all moves.
Complete the function roverMove in the editor.
roverMove has the following parameter(s):
- 1.
int n: the size of the square matrix - 2.
String[] cmds: the commands
Returns
int: the label of the cell the rover occupies after executing all commands
1Example 1

Constraints
Limits and guarantees your solution can rely on.
- 2 ≤ n ≤ 20
- 1 ≤ |cmds| ≤ 20