As reported: Apple IS&T Reliability Engineering intern (India, 2025), round 1 — technical, about 50 minutes on CoderPad: rotate a matrix 90 degrees clockwise (coded live), among other DSA questions.
You are given an n x n matrix. Rotate it by 90 degrees clockwise, in place — modify the input matrix directly; do not allocate another matrix.
This is LeetCode 48 — Rotate Image.
Example 1
[[1,2,3], [[7,4,1],
[4,5,6], -> [8,5,2],
[7,8,9]] [9,6,3]]
Example 2
[[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
-> [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
Constraints: 1 ≤ n ≤ 20; −1000 ≤ matrix[i][j] ≤ 1000.
Code runner format: one JSON value per line: matrix (LeetCode's test-case format). Implement rotate(matrix); it returns nothing — the harness prints the matrix after your call.