Pascal's Triangle Construction
You are provided with an integer 'N'. Your task is to generate a 2-D list representing Pascal’s triangle up to the 'N'th row.
Pascal's triangle is a triangular array where each element is the sum of the two directly above it from the preceding row, representing binomial coefficients.
Example:
Input:
N = 4
Output:
[ [1], [1, 1], [1, 2, 1], [1, 3, 3, 1] ]
Explanation:
In the third row, for example, the second element is calculated as follows: 2 = 1 + 1. Similarly, in the fourth row, the numbers 3 are derived: 3 = 1 + 2 and 3 = 2 + 1.
Constraints:
1 ≤ T ≤ 40
1 ≤ N ≤ 50
- Time Limit: 1 sec
Be the first one to answer
Add answer anonymously...
>
JPMorgan Chase & Co. R&D Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

