Grokking Data Structures & Algorithms for Coding Interviews
0% completed
Solution: Rotate an Image
Problem Statement
Rotate an n x n matrix by 90 degrees clockwise, in place, and return it.
Examples
Example 1
- Input: matrix =
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] - Expected Output:
[[7, 4, 1], [8, 5, 2], [9, 6, 3]]
Example 2
- Input: matrix =
[[1, 2], [3, 4]] - Expected Output:
[[3, 1], [4, 2]]
Example 3
- Input: matrix =
[[5]] - Expected Output:
[[5]]
Where the answer comes from
Write down where one value has to end up. The value at row r, column c moves to row c, column n - 1 - r
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%