Back to DSA sheet

Pascal's Triangle

EasyArrays
Open on LeetCodeAmazonAppleGoogle

Generate the first numRows of Pascal's triangle. Each number is the sum of the two numbers directly above it; the edges are 1.

Input format (stdin): a single integer numRows. Output each row on its own line, values space separated.

Examples
Input: 5
Output: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Each interior value is the sum of the two above it.
Input: 1
Output: 1
Constraints
  • 1 <= numRows <= 30
Sheets
Grind 75Striver A2Z
pascals-triangle.cpp2 sample tests
Loading editor
Test results

Run the sample tests to check your solution against expected output.

Custom input (stdin)
Output

Run your code to see its output.