Pascal's Triangle II
Real-world version: Row Of The Drop BoardThe 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.
def board_row(level: int) -> list[int]:public List<Integer> boardRow(int level)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's