Apply commands to transform a matrix
Company: Capital One
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
You are given an integer matrix `A` of size `n × m` and a list of string commands to apply in order. Implement the commands and return the final matrix.
## Commands
Each command is one of:
1. `"reverseRow r"`
- `r` is a 0-based row index.
- Reverse the elements in row `r` in-place.
2. `"swap r1 r2"`
- `r1` and `r2` are 0-based row indices.
- Swap the two rows.
3. `"rotate"`
- Rotate the entire matrix 90 degrees clockwise.
- Note that after rotation, the matrix dimensions become `m × n`.
## Input/Output
- Input: `A` and `commands`.
- Output: the matrix after applying all commands in order.
## Assumptions / Constraints
- `0 ≤ r, r1, r2 < current_number_of_rows` at the time the command is executed.
- Matrix elements fit in 32-bit signed integers.
- `n, m ≥ 1`.
## Example
If `A = [[1,2,3],[4,5,6]]` and `commands = ["reverseRow 0", "rotate"]`, then:
- After `reverseRow 0`: `[[3,2,1],[4,5,6]]`
- After `rotate`: `[[4,3],[5,2],[6,1]]`
Return `[[4,3],[5,2],[6,1]]`.
Quick Answer: This question evaluates array and matrix manipulation skills, specifically in-place row reversal, row swapping, and 90-degree rotation, and falls under the Coding & Algorithms domain with emphasis on practical implementation.