Loading...
Loading...
Loading...
A photo is stored as a grid of pixel values with r rows and c columns. Rotate it 90 degrees clockwise. The result has c rows and r columns: the first column of the photo, read from bottom to top, becomes the first row.
Example 1
Input
2 3 1 2 3 4 5 6
Output
4 1 5 2 6 3
Column 1 read upwards is 4 1, column 2 is 5 2, column 3 is 6 3.
Example 2
Input
3 3 1 2 3 4 5 6 7 8 9
Output
7 4 1 8 5 2 9 6 3
Try the problem first. Open one hint at a time.
Make a new grid rot with c rows and r columns.
Work out where one pixel goes: photo[i][j] lands in row j of the result, at column r - 1 - i.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor