A digital photo frame stores a square N-by-N image as a grid of integer pixel codes. The user taps the rotate button once, which turns the image a quarter turn clockwise (90 degrees to the right).
After a clockwise quarter turn, the pixel that was in row i, column j moves to row j, column N-1-i. Equivalently, the first column of the original (read bottom-to-top) becomes the first row of the result (read left-to-right).
Print the rotated grid.
Line 1: a single integer N, the side length.
Next N lines: each contains N space-separated integers (one grid row).
N lines, each with N space-separated integers: the grid after one clockwise quarter turn.
Example 1
Input
3 1 2 3 4 5 6 7 8 9
Expected
7 4 1 8 5 2 9 6 3
Explanation
The first column (1,4,7) becomes the top row read left to right (7 4 1); continuing column by column, the result is [[7,4,1],[8,5,2],[9,6,3]].
Example 2
Input
1 5
Expected
5
Explanation
A single-pixel image is unchanged by rotation.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →