Ctrl K

Rows of the Number Pyramid

Easy
The number pyramid (also known as Pascal's triangle) is built like this: the top row is a single 1; each next row is one number longer, has 1 at both ends, and every inner number equals the sum of the two numbers just above it to the left and to the right. Given rows, return the first rows rows of the pyramid from the top down, as a list of lists.
Example 1
rows=4 → [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]

The third row is [1, 2, 1]; below it come 1, 1 + 2 = 3, 2 + 1 = 3, 1.

Example 2
rows=2 → [[1], [1, 1]]
Constraints
  • 1 ≤ rows ≤ 30
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Single Row of the Number Pyramid EasySingle Trade Profit EasyCheapest Climb to the Top EasyAlternating Team Picks EasyWater Between Walls Hard
loading Python…
Input
rows=4
Expected
[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]

Run checks the first 3 tests in your browser. Submit checks all 18 tests on the server, hidden ones included.