===== ISTEM =====
Solve the following programming task.

TASK: Rotate a 2D Matrix 90 Degrees Clockwise

Write a function 'rotate_matrix(matrix)' that rotates an N x N two-dimensional matrix by 90 degrees clockwise in place.

STARTER CODE (python):
def rotate_matrix(matrix: list[list[int]]) -> list[list[int]]:
    # Write your code here
    pass


RULES:
- Keep the function name and signature EXACTLY as given.
- Return working code only. No explanations.
- Put the code in a single ``` block.
- Try to solve it first. If you genuinely cannot, write only this single
  line instead of producing faulty code: CANNOT_SOLVE

===== HAM YANIT =====
```python
def rotate_matrix(matrix: list[list[int]]) -> list[list[int]]:
    n = len(matrix)
    for i in range(n // 2):
        for j in range(i, n - 1 - i):
            matrix[i][j], matrix[j][n - 1 - i], matrix[n - 1 - i][n - 1 - j], matrix[n - 1 - j][i] = \
                matrix[n - 1 - j][i], matrix[i][j], matrix[j][n - 1 - i], matrix[n - 1 - i][n - 1 - j]
    return matrix
```