Problem · Medium · 20 min
Turn the picture
- Medium
- Grids
- Arrays
A picture is a grid of values. The grid is an array of rows, and every row has the same length.
Write rotateRight(grid). It returns a new grid that shows the same picture after a quarter turn clockwise (90 degrees to the right).
For example, this grid:
1 2 3
4 5 6
becomes this grid after the turn:
4 1
5 2
6 3
In code, [[1, 2, 3], [4, 5, 6]] becomes [[4, 1], [5, 2], [6, 3]].
- The grid does not have to be a square.
- An empty grid gives an empty grid.
Examples
| Call | Result |
|---|---|
rotateRight([[1, 2, 3], [4, 5, 6]]) |
[[4, 1], [5, 2], [6, 3]] |
rotateRight([[1, 2], [3, 4]]) |
[[3, 1], [4, 2]] |
rotateRight([]) |
[] |
Tasks
2 to do
Task 1, not checked yet. Make
rotateRightpass the example tests.Task 2, not checked yet. Make
rotateRightpass the hidden tests.
Task 1 of 2
Make rotateRight pass the example tests.