A data logger stores its readings as a grid, but every analysis wants them laid out differently. Rather than retype them, you write a helper that lays the same readings into a new grid.
Task: write relayout(grid, rows, cols):
grid in reading order: the first row left to right, then the second row, and so on.rows rows and cols columns, filling the first row left to right, then the next row, and so on.Either rows or cols may be -1, meaning "whatever number makes this fit".
If the new layout can't hold exactly the readings — with nothing left over and no gaps — return None instead. That includes the case where rows and cols are both -1, since then more than one layout would fit.
Apart from -1, rows and cols are always positive whole numbers. grid has at least one value and all its rows are the same length.
Example