Rotate a square matrix
Return a new matrix rotated clockwise by 90 degrees. Input is square; empty input returns [].
matrix = [[1, 2], [3, 4]]
n, row, column = 2, 0, 1
print(matrix[n-1-column][row])Reason about the state
An output cell at row r, column c comes from input row n-1-c, column r. Construct rows independently to avoid shared references. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return a new matrix rotated clockwise by 90 degrees. Input is square; empty input returns [].
The explanation opens here once every check passes.