Problem

Given n, return a length n*n array flattened row by row: row i (0-based) has i+1 ones on the left and zeros after (see examples).

Examples

  • fillSquare(2) -> [0, 1, 2, 1]
  • fillSquare(3) -> [0, 0, 1, 0, 2, 1, 3, 2, 1]
Compile and test (Ctrl+Enter)