@@ -17,52 +17,52 @@ Output: [[7,4,1],[8,5,2],[9,6,3]]
1717## Approach
1818
1919### Method 1: Transpose + Reverse (Recommended)
20- 1 . Transpose the matrix (swap rows and columns )
20+ 1 . Transpose the matrix (swap matrix [ i ] [ j ] with matrix [ j ] [ i ] )
21212 . Reverse each row
22223 . Most efficient approach
2323
2424** Time Complexity:** O(n²) - Two passes
2525** Space Complexity:** O(1) - In-place modification
2626
27- ### Method 2: Layer by Layer Rotation
27+ ### Method 2: Layer by Layer
28281 . Rotate matrix layer by layer
29292 . Use four-way swap for each layer
30303 . Less efficient than transpose approach
3131
32- ** Time Complexity:** O(n²) - Two passes
32+ ** Time Complexity:** O(n²) - Single pass
3333** Space Complexity:** O(1) - In-place modification
3434
3535## Algorithm
3636
3737```
38381. Transpose matrix: matrix[i][j] = matrix[j][i]
39- 2. Reverse each row: matrix[i][j] = matrix[i][n-1-j]
39+ 2. Reverse each row: reverse( matrix[i])
4040```
4141
4242## Key Insights
4343
44- - ** Transpose** : Swap rows and columns
44+ - ** Transpose** : Swap elements across diagonal
4545- ** Reverse** : Reverse each row after transpose
46- - ** Local Optimum ** : Efficient matrix transformation
47- - ** Global Optimum ** : 90-degree clockwise rotation
46+ - ** In-place ** : No extra space needed
47+ - ** Space Optimization ** : Use only necessary space
4848
4949## Alternative Approaches
5050
51511 . ** Layer by Layer** : Rotate layer by layer
52522 . ** Four-way Swap** : Use four-way swap for each element
53- 3 . ** Brute Force ** : Create new matrix and copy
53+ 3 . ** Mathematical ** : Use mathematical transformation
5454
5555## Edge Cases
5656
57- - Single element: Return as is
58- - 2x2 matrix: Handle appropriately
57+ - Single element: No change needed
58+ - 2x2 matrix: Simple swap
5959- Large matrix: Handle efficiently
60- - Empty matrix: Return empty matrix
60+ - Empty matrix: Handle appropriately
6161
6262## Applications
6363
64- - Matrix algorithms
6564- Image processing
65+ - Matrix operations
6666- Algorithm design patterns
6767- Interview preparation
6868- System design
@@ -72,4 +72,4 @@ Output: [[7,4,1],[8,5,2],[9,6,3]]
7272- ** Transpose + Reverse** : Most efficient approach
7373- ** Space Optimization** : O(1) space complexity
7474- ** Quadratic Time** : O(n²) time complexity
75- - ** No Extra Space** : Use only necessary space
75+ - ** No Extra Space** : Use only necessary space
0 commit comments