FunctionRacerProblemsRace

Mirror the Rows

BeginnerGridsPython, JavaScript, TypeScript, Java, C++

Return the mirror image of grid, as if a mirror stood at its right edge: every row is read backwards, so the first column becomes the last one. The rows stay in their order from top to bottom.

Build a new grid and leave grid itself unchanged.

Example 1

grid [[1,2,3],[4,5,6]]
returns [[3,2,1],[6,5,4]]

Each row is reversed on its own: [1, 2, 3] becomes [3, 2, 1] and [4, 5, 6] becomes [6, 5, 4].

Example 2

grid [[7]]
returns [[7]]

A single cell is its own mirror image.

Example 3

grid [[1],[2],[3]]
returns [[1],[2],[3]]

With one column there is nothing to swap, and the rows do not change places.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems