Pascal's Triangle — generating all rows up to numRows — is a foundational DP array construction problem. Each element is the sum of the two elements directly above it, forming a triangular grid that represents binomial coefficients. This appears across combinatorics, probability, and algorithm design. The array and dynamic programming interview pattern is the building block for many other problems.
Apple, Cisco, Goldman Sachs, Microsoft, Meta, Amazon, Google, Bloomberg, and Adobe ask this because it tests 2D array construction, recurrence relations, and boundary handling — all fundamental programming skills. The problem is also a gateway to understanding combinations and binomial theorem applications.
Row-by-row construction. For each row i: create a new row of length i+1. Set first and last elements to 1. For positions j=1..i-1: row[j] = prev_row[j-1] + prev_row[j]. Append each row to the result.
numRows=4. Build progressively:
Pascal's Triangle is more than a DP warm-up — it's a gateway to binomial coefficients C(n,k). Understanding that triangle[n][k] = C(n,k) connects this to combinatorics. Practice generating it iteratively, verifying with small cases (row 4 = [1,4,6,4,1]), and recognizing its applications in probability calculations and polynomial expansion.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Min Cost Climbing Stairs | Easy | Solve | |
| Pascal's Triangle II | Easy | Solve | |
| Pascal's Triangle | Easy | Solve | |
| Best Time to Buy and Sell Stock | Easy | Solve | |
| Pascal's Triangle II | Easy | Solve |