Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Pascal's Triangle

Easy
arraymathsimulation

Generate the first n rows of Pascal's triangle, where every number is the sum of the two directly above it.

Input: one line, the integer n. Output: n lines — row i contains i space-separated integers.

Example 1
Input:
5
Output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Example 2
Input:
1
Output:
1

Constraints

  • 1 ≤ n ≤ 30
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.