#213EasyMatrix· Index Mapping for Rotation
Rotate Tile Grid
Input format
`grid`: a non-empty rectangular grid of integers.
Output format
A new grid with `grid[0].length` rows and `grid.length` columns holding the rotated pattern.
Examples
Input: grid = [[1, 2, 3], [4, 5, 6]]
Output: [[4, 1], [5, 2], [6, 3]]
The first column read from the bottom up (4, 1) becomes the first row, the second column becomes the second row, and so on. A 2 x 3 grid turns into a 3 x 2 grid.
Input: grid = [[1, 2], [3, 4]]
Output: [[3, 1], [4, 2]]
For a square grid the corners travel one step around: 1 moves to the top-right, 2 to the bottom-right, 4 to the bottom-left and 3 to the top-left.
Input: grid = [[9]]
Output: [[9]]
A single tile is unchanged.
Constraints
- 1 <= grid.length, grid[0].length <= 100
- All rows have the same length.
- -10^4 <= grid[r][c] <= 10^4
- #matrix
- #rotation
- #index-mapping
- #arrays