Easy
Pascal's Triangle
Easy
0 submissions
10 coins
+50 XP
Array
Dynamic Programming
Problem Description
## Problem
Given an integer `numRows`, return the first `numRows` of **Pascal's triangle**.
In Pascal's triangle, each number is the sum of the two numbers directly above it. The edges of each row are always 1.
```
[1]
[1,1]
[1,2,1]
[1,3,3,1]
[1,4,6,4,1]
```
## Examples
**Example 1:**
```
Input: numRows = 5
Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
```
**Example 2:**
```
Input: numRows = 1
Output: [[1]]
```
## Hints
- Start with the base case: the first row is always `[1]`.
- For each subsequent row, the first and last elements are 1.
- Every interior element at index `j` equals `prev_row[j-1] + prev_row[j]`.
Constraints
- `1 <= numRows <= 30`
Need help?
Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.
Video Call
Whiteboard
Live Coding
Screen Share