← DiffPush

Pascal triangle

DiffPush Tier Arrays · Hard O(rowIndex) · O(rowIndex) for the row being returned

Rebuilding One Row of a Growth Simulator

A population growth simulator keeps a triangular table where every entry is the sum of the two entries directly above it. A checkpoint stored only the row depth, and the restore job must regenerate that row alone. Reproduce the requested row without materialising the whole table.

Input: A single integer rowIndex, where row 0 is the apex of the triangle.

Output: The rowIndex-th row of the triangle as an array of rowIndex + 1 integers.

Constraints

Examples

Example 1

Input: {"rowIndex":3}
Output: [1,3,3,1]
Each interior entry is the sum of its two parents in the row above, giving 1,3,3,1.

Example 2

Input: {"rowIndex":1}
Output: [1,1]
The first row below the apex holds two 1s, and both edges of every row are always 1.

Solve this in your browser →

Also on LeetCode ↗