Rotate a Matrix Clockwise
Given a rectangular matrix with r rows and c columns, return a new matrix that is the original turned 90 degrees clockwise. The result has c rows and r columns.
The first row of the result is the first column of the input read from bottom to top.
Example 1
Input: matrix = [[1,2],[3,4]] Output: [[3,1],[4,2]]
Example 2
Input: matrix = [[1,2,3]] Output: [[1],[2],[3]]
Constraints
- 0 <= r, c <= 100
- All rows have the same length.
Hint 1
Column j of the input becomes row j of the output.
Hint 2
Read each column from the last row up to the first.
Good practice for: Game Developer, Frontend Developer, Machine Learning Engineer, Data Scientist, Mobile App Developer
Run checks your code on 3 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.