Asked inJPMorgan Chase & Co.,R&D Intern

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
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter