Given a grid grid and a string axis, return a new grid that is the mirror image of the input:
axis == "h": mirror left-to-right (each row is reversed).axis == "v": mirror top-to-bottom (the order of the rows is reversed).
Examples
Input: grid = [[1, 2, 3],
[4, 5, 6]], axis = "h"
Output: [[3, 2, 1],
[6, 5, 4]]
Input: grid = [[1, 2, 3],
[4, 5, 6]], axis = "v"
Output: [[4, 5, 6],
[1, 2, 3]]
Constraints
1 <= rows, cols <= 100axisis always"h"or"v"- The input grid must not be modified, and the result must not share any row with it. One test
calls
grid_after(grid, axis), which runs yourflip, writes0into every cell of the result, and then returnsgriditself, so it must come back unchanged.
Goals
- Reverse rows or the row order based on a flag
- Return a copy rather than mutating the input