Problem 273065 · easy · Phase 02 Linear Data Structures

Rotate a Grid Clockwise

2d-lists · rotation · indexing

Given a rectangular grid grid with R rows and C columns, return a new grid that is the input rotated 90 degrees clockwise. The result has C rows and R columns. The first column of the input (read bottom to top) becomes the first row of the output.

Examples

Input:  grid = [[1, 2, 3],
                [4, 5, 6]]
Output: [[4, 1],
         [5, 2],
         [6, 3]]

Input:  grid = [[1, 2],
                [3, 4]]
Output: [[3, 1],
         [4, 2]]

Constraints

  • 1 <= rows, cols <= 100
  • Return a new grid; do not modify the input.

Goals

  • Work out where each cell lands after a quarter turn
  • Produce an output whose shape is cols x rows
Starting Python…