December 27, 2024 |2.3K Views

Rotate a Matrix by 180 degree

Explore Courseexplore course icon
Description
Discussion

Rotate a matrix by 180 degrees involves reversing the elements of the matrix. After rotation, elements are moved to the opposite positions, such as mat[i][j] moving to mat[n-i-1][n-j-1]. Two main approaches are used: rotating 90 degrees twice or using an auxiliary matrix. An optimized method swaps elements in place, reducing space complexity. If the matrix has an odd dimension, the middle row elements are reversed.

For more details, visit GeeksforGeeks article here.