Intermediate Level
Implement the rotateImageClockwise method that returns the matrix after rotating it 90 degrees clockwise.
The input contains a square matrix matrix of size n × n.
Your task is to rotate the matrix 90 degrees clockwise and return the rotated matrix.
For example, [[1,2],[3,4]] becomes [[3,1],[4,2]] after a clockwise rotation.
A simple approach is to create a new matrix and place every value in its rotated position.
For a value at position [row][col] in the original matrix, its clockwise rotated position is [col][n - 1 - row] in the result matrix.
Fill the result matrix using this formula and return it.
Pseudocode:
function rotateImageClockwise(matrix, n):
result = create n by n matrix
for row from 0 to n - 1:
for col from 0 to n - 1:
newRow = col
newCol = n - 1 - row
result[newRow][newCol] = matrix[row][col]
return result