Problem 229182 · easy · Phase 02 Linear Data Structures

Right-Aligned Staircase

2d-lists · patterns · list-construction

Given an integer n, build an n x n grid of 0s and 1s that draws a staircase climbing from the top-right corner: row i (0-based) has 1 in its last i + 1 cells and 0 everywhere else.

Examples

Input:  n = 3
Output: [[0, 0, 1],
         [0, 1, 1],
         [1, 1, 1]]

Input:  n = 1
Output: [[1]]

Constraints

  • 0 <= n <= 100; n = 0 gives []

Goals

  • Generate a grid from a size instead of transforming one
  • Relate a row index to how many cells it fills
Starting Python…