Rotate Matrix Over Diagonals
Learn this problemProblem statement
tomtom's note: Feel free to check out the source image below for the original problem statement :)
Imagine you have a beautiful square matrix and a number, turns. Your mission is to gracefully rotate this matrix turns times "over its diagonals," creating a new, enchanting pattern with each rotation. After you've completed the rotations, you'll return the transformed matrix, now dressed in its new, elegant arrangement. 🌟
The elements along the two main diagonals remain beautifully in place, untouched by the rotation. However, the four sections formed by these diagonals gracefully swap positions in a clockwise dance. With each rotation, these segments move to their new spots, creating a fresh, charming pattern. Take a look at the images below to see this elegant transformation in action! 🌼
ദ്ദി(˵ •̀ ᴗ - ˵ ) ✧ Credit to robot ༊࿐ ͎. 。˚ ° ˚🧡.
Function
rotateMatrixOverDiagonals(matrix: int[][], turns: int) → int[][]Examples
Example 1
matrix = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20],[21, 22, 23, 24, 25]]turns = 1return = [[1, 16, 11, 6, 5], [22, 7, 12, 9, 2], [23, 18, 13, 8, 3], [24, 17, 14, 19, 4], [21, 20, 15, 10, 25]]
Constraints
🐰More Capital One problems
- Compare Counts Around PivotOA · Seen Jul 2026
- Format a Newspaper PageOA · Seen Jul 2026
- Laser Robot Safe PathOA · Seen Jul 2026
- Match Consecutive Word BoundariesOA · Seen Jul 2026
- Reconstruct Landmark JourneyOA · Seen Jul 2026
- Rightmost Longest Character RunOA · Seen Jul 2026
- Track Received Byte RangesOA · Seen Jul 2026
- Alternate String EndsOA · Seen Jul 2026