FunctionRacerProblemsRace

Enlarge the Picture

BeginnerGridsPython, JavaScript, TypeScript, Java, C++

grid is a small picture given as a list of rows, each cell holding a colour number. Enlarge it k times in both directions: every cell becomes a square block of k rows and k columns that all hold that cell's value, and the blocks keep the same arrangement as the cells. A picture with R rows and C columns becomes one with R * k rows and C * k columns. Return the enlarged picture as a new grid; grid itself must not be changed.

Example 1

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

Each cell becomes a 2 by 2 block, so the 2 by 2 picture becomes 4 by 4.

Example 2

grid [[5,0,7]]
k 3
returns [[5,5,5,0,0,0,7,7,7],[5,5,5,0,0,0,7,7,7],[5,5,5,0,0,0,7,7,7]]

Each of the three cells becomes a 3 by 3 block, which gives 3 rows of 9 values.

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