Trains the technique from
LeetCode 2022Convert 1D Array Into 2D ArrayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A run of tiles is to be laid into a rack of rows shelves, each shelf holding cols slots. Fill the rack shelf by shelf from the top, and within each shelf from left to right, taking the tiles in the order they are given.
Return the filled rack. When the run of tiles does not fill the rack exactly, return an empty list.
Example 1
Six tiles fill two shelves of three slots, taken in order along the top shelf and then the bottom one.
Example 2
Five tiles cannot fill a rack of four slots, whichever way they are laid, so nothing is returned.
Example 3
Five shelves of a single slot take the tiles one at a time in the order given.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def construct2_d_array(tiles: list[int], rows: int, cols: int) -> list[list[int]]:public int[][] construct2DArray(int[] tiles, int rows, int cols)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.