
Asked in Capgemini
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...
Top Senior Software Engineer Interview Questions Asked at Capgemini
Q. What coding languages are you well-versed in?
Q. Write SQL queries demonstrating the use of GROUP BY and HAVING clauses.
Q. What is the difference between a hash set and a tree set?
Interview Questions Asked to Senior Software Engineer at Other Companies
Top Skill-Based Questions for Capgemini Senior Software Engineer
Web Development Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 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

