Skip to the code
cf.
+10 XP

#650 Binomial Smoothing Weights

easy

A charting library smooths a line with binomial weights. For a window of size k + 1, the weights are C(k, 0), C(k, 1), ..., C(k, k), which is row k of Pascal's triangle.

Write binomialRow(k) that returns that row as an array.

Example 1

Input: k = 4
Output: [1,4,6,4,1]

Each inner number is the sum of the two above it in the previous row, [1, 3, 3, 1].

Example 2

Input: k = 0
Output: [1]

Row 0 is just [1].

Constraints

  • 0 <= k <= 30
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).