Skip to content
BytePatterns

One Row of Pascal's Triangle

EasyMath & Number Theory#binomial-coefficients#multiplicative-formula~15m

Problem

A probability library needs every binomial coefficient from C(k, 0) through C(k, k) for a given k, which is row k of Pascal's triangle counting from row 0. Given k between 0 and 1,000, return that row as a list of integers. Build it in O(k) arithmetic steps without building the rows above it.

Examples

Input:  k = 3
Output: [1, 3, 3, 1]
Input:  k = 5
Output: [1, 5, 10, 10, 5, 1]
Input:  k = 0
Output: [1]
Why:    edge case, row 0 holds a single 1

Hints

0 / 3

Stuck on the idea rather than the code? Permutations vs Combinations covers it.