Rotate matrix
Hereβs the clean summary β no code, just concepts:
π Transpose
-
Swap matrix[r][c] with matrix[c][r]
-
Reflects matrix across the main diagonal
-
Rows become columns
π Row Reverse
-
Reverse elements inside each row
-
Flips matrix left β right
-
Horizontal flip
π Column Reverse
-
Reverse elements inside each column
-
Flips matrix top β bottom
-
Vertical flip
π Rotations (NxN Matrix)
β 90Β° Clockwise
-
Transpose
-
Then reverse each row
β 180Β°
-
Reverse rows (top β bottom)
-
Then reverse each row
-
Order does not matter
β 270Β° Clockwise (same as 90Β° CCW)
-
Transpose
-
Then reverse each column
π§ Mental Shortcut
-
Transpose = diagonal flip
-
Row reverse = horizontal flip
-
Column reverse = vertical flip
-
Combine flips to get rotation
Thatβs the whole rotate-matrix game.