Generating Pascal's Triangle
Given an integer N
, generate a 2-D array list representing Pascal's Triangle up to the N-th row.
An element in Pascal's Triangle is the sum of the two elements directly above it in the previous row. The triangle also represents binomial coefficients.
Input:
The first line contains an integerT
, the number of test cases.
Each test case consists of a single integerN
, representing the number of rows in the Pascal's Triangle to be returned.
Output:
For each test case, return a 2-D array list containing Pascal's Triangle up to row N
.
Example:
Input:
T = 1 N = 4
Output:
[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]
Explanation:
For N = 4
, the Pascal's Triangle is:
[
[1],
[1, 1],
[1, 2, 1],
[1, 3, 3, 1]
]
Each element is obtained by summing the two directly above it.
Constraints:
1 <= T <= 40
1 <= N <= 50
- Time Limit: 1 sec
Note:
The implementation function should return the result, not print it.
Be the first one to answer
Add answer anonymously...
Top INCA INFOTECH TECHNOLOGIES Software Developer interview questions & answers
Popular interview questions of Software Developer
>
INCA INFOTECH TECHNOLOGIES Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app