Skip to the code
cf.
+10 XP

#566 Bezier Weight Row

easy

A Bezier curve of degree degree, like the cubic curves behind CSS cubic-bezier() timing functions, weights its control points with binomial coefficients: the numbers in row degree of Pascal's triangle. Each number in the triangle is the sum of the two numbers above it, and every row starts and ends with 1.

Write bezierWeights(degree) that returns row degree of Pascal's triangle as an array. Row 0 is [1].

Example 1

Input: degree = 3
Output: [1,3,3,1]

The cubic weights: row 2 is [1, 2, 1], and each inner number of row 3 adds two neighbors from it.

Example 2

Input: degree = 0
Output: [1]

Row 0 is a single 1.

Constraints

  • 0 <= degree <= 33
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).