Ctrl K

A Single Row 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. Rows are numbered from 0 at the top. Given level, return the row of the pyramid with that number. Bonus: can you do it with only O(level) extra memory?
Example 1
level=4 → [1, 4, 6, 4, 1]

Rows from level 0: [1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1].

Example 2
level=0 → [1]

The top row is a single 1.

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

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