Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Pascal's Triangle

XPChallenge Points: 10
levelLevel: Easy

You are given an integer n, representing the number of rows to generate in Pascal’s Triangle.
In Pascal’s Triangle:
• The first and last element of each row is always 1.
• Every other element is the sum of the two numbers directly above it in the previous row.
Your task is to return a 2D list representing the first n rows of Pascal’s Triangle.

Example 1:

Input: n = 6

Output: [ [1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1] ]

Example 2:

Input: n = 3

Output: [ [1], [1, 1], [1, 2, 1] ]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result