Problem 339147 · easy · Phase 03 Linear Management & Searching

Rows of the Binomial Triangle

matrix · iteration · list building

The binomial triangle starts with the single row [1]. Every later row begins and ends with 1, and each interior entry is the sum of the two entries directly above it. Given a non-negative integer n, return the first n rows as a list of lists.

Examples

Input:  n = 4
Output: [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]

Input:  n = 0
Output: []

Constraints

  • 0 <= n <= 200 (entries grow large; Python integers handle this)
  • Target: O(n^2) time.

Goals

  • Build each row from the previous one
  • Handle the borders of a row separately from the interior
  • Return an empty result for zero rows
Starting Python…