Layer Labels
Build a grid with rows rows and cols columns in which every cell holds its layer number. The cells on the outer edge (the first row, the last row, the first column and the last column) are layer 0. Without them, what is left is a smaller rectangle whose own edge cells are layer 1, and so on inward. In other words, the layer of the cell in row r and column c is its distance to the nearest edge: the smallest of r, c, rows - 1 - r and cols - 1 - c. Return the grid as a list of rows, top row first.
Example 1
The edge cells are layer 0 and the six cells inside them form layer 1.
Example 2
The centre cell of a 5 by 5 grid is two steps from every edge, so it is layer 2.
Constraints
1 <= rows <= 101 <= cols <= 10
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Mirror the RowsBeginner
- Rising DiagonalBeginner
- Snake ReadBeginner
- Spot the DifferencesBeginner
- Square on a Winding BoardBeginner
- Colony StepEasy
- Diagonal BandsEasy
- Fenced RobotEasy