FunctionRacerProblemsRace

Diagonal Bands

EasyGridsPython, JavaScript, TypeScript, Java, C++

Group the cells of grid by the sum of their row index and column index. Return a list of lists: the first inner list holds the cell with row + col = 0, the next holds the cells with row + col = 1, and so on up to the bottom-right cell. Inside each inner list, order the cells by increasing row, that is, from the top-right end of the band to its bottom-left end.

Example 1

grid [[1,2,3],[4,5,6],[7,8,9]]
returns [[1],[2,4],[3,5,7],[6,8],[9]]

The band with row + col = 2 has (0, 2) = 3, (1, 1) = 5 and (2, 0) = 7, in that order.

Example 2

grid [[1,2,3,4],[5,6,7,8]]
returns [[1],[2,5],[3,6],[4,7],[8]]

With two rows no band has more than two cells; the last band holds only (1, 3) = 8.

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