Show problems as
Classic problem #119EasyArrayDynamic Programming

Pascal's Triangle II

Real-world version: Row Of The Drop Board
Tracked in this browser only
Read Pascal's Triangle II on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A drop board is laid out as a triangle of cells. The top row is row 0 and holds a single cell containing 1.

Each row below has one cell more than the row above it. The cell at each end of a row holds 1, and every other cell holds the total of its two neighbours in the row above.

Given level, return the contents of row level, read from left to right.

Examples

Example 1

Input
level = 4
Output
[1, 4, 6, 4, 1]

Row 3 reads 1, 3, 3, 1. Row 4 is one cell longer, holds 1 at each end, and its inner cells hold 1 + 3 = 4, 3 + 3 = 6 and 3 + 1 = 4.

Example 2

Input
level = 6
Output
[1, 6, 15, 20, 15, 6, 1]

Row 5 reads 1, 5, 10, 10, 5, 1, so the inner cells of row 6 hold 6, 15, 20, 15 and 6, with 1 at each end.

Example 3

Input
level = 8
Output
[1, 8, 28, 56, 70, 56, 28, 8, 1]

Row 7 reads 1, 7, 21, 35, 35, 21, 7, 1, and totalling its neighbouring pairs gives the inner cells 8, 28, 56, 70, 56, 28 and 8, with 1 at each end.

Constraints

  • 0 <= level <= 33
  • Every number in the answer fits in a signed 32-bit integer.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def board_row(level: int) -> list[int]:
Java
public List<Integer> boardRow(int level)