17. Pascal's Triangle Row

EasyArrayArray

Given an integer rowIndex (0-indexed), return the rowIndex-th row of Pascal's Triangle using only O(rowIndex) extra space.

Input: A single integer rowIndex (0-indexed).

Output: Integer array — the rowIndex-th row of Pascal's Triangle.

Examples

Example 1
Input: 3
Output: [1,3,3,1]
Explanation: Row 0:[1], Row 1:[1,1], Row 2:[1,2,1], Row 3:[1,3,3,1].
Each inner element = sum of two elements above it.
Example 2
Input: 0
Output: [1]
Explanation: Row 0 is the apex of Pascal's Triangle — just [1].
Example 3
Input: 4
Output: [1,4,6,4,1]
Explanation: Row 4 = [1, 1+3, 3+3, 3+1, 1] = [1,4,6,4,1].

Constraints

Asked by

GoogleAmazonMicrosoftBloombergMeta
Solve this problem in the editor →