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

AnswerBot
4mo
Generate Pascal's triangle up to the Nth row using a 2-D list.
Iterate through each row up to N, starting with [1] as the first row.
Calculate each element in a row by summing the two elements directly ...read more
Saurabh Kumar
2y
currently not working
answer = [] for row in range(numRows): ans = 1 ansRow = [1] for col in range(row): ans *= row - col ans //= col + 1 ansRow.append(ans) answer.append(ansRow) return answer
Help your peers!
Add answer anonymously...
Capgemini Senior Software Engineer interview questions & answers
A Senior Software Engineer was asked 1w agoQ. What coding languages are you well-versed in?
A Senior Software Engineer was asked 1mo agoQ. Write SQL queries demonstrating the use of GROUP BY and HAVING clauses.
A Senior Software Engineer was asked 1mo agoQ. Find the first duplicate character from a string using Java streams.
Popular interview questions of Senior Software Engineer
A Senior Software Engineer was asked 2w agoQ1. What coding languages are you well-versed in?
A Senior Software Engineer was asked 1mo agoQ2. Write SQL queries demonstrating the use of GROUP BY and HAVING clauses.
A Senior Software Engineer was asked 1mo agoQ3. Find the first duplicate character from a string using Java streams.
Top HR questions asked in Capgemini Senior Software Engineer
A Senior Software Engineer was asked 8mo agoQ1. Why do you want to join Capgemini?
A Senior Software Engineer was asked 8mo agoQ2. Tell me about yourself.
A Senior Software Engineer was asked 10mo agoQ3. What are the metrics used in your project?
>
Capgemini Senior Software Engineer 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

