Pascal's Triangle
Updated
Problem statement
For this exercise, assume the task is to return the first numRows rows of Pascal's triangle as an array of rows.
The first row is [1]. Every later row starts and ends with 1; each interior value is the sum of the two values directly above it. Return an empty array when numRows is zero.
Function
generateTriangle(numRows: int) → int[][]Examples
Example 1
numRows = 5return = [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]The fifth row is [1,4,6,4,1]: its interior entries are 1 + 3, 3 + 3, and 3 + 1 from the previous row.
Example 2
numRows = 1return = [[1]]Only the first row is requested.
Example 3
numRows = 0return = []Zero requested rows give an empty array.
Constraints
0 <= numRows <= 30- Every returned value fits in a signed 32-bit integer.
More JP Morgan Chase Onsite Interview questions
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU CacheONSITE INTERVIEW · Seen Nov 2026
- Employees Above Average SalaryONSITE INTERVIEW · Seen Sep 2026
- Highest-Earning Employees By DepartmentONSITE INTERVIEW · Seen Sep 2026
- K Largest Integers in Descending OrderONSITE INTERVIEW · Seen Aug 2026
- Tile a Three-Row Board with DominoesONSITE INTERVIEW · Seen Jan 2026
- Two SumONSITE INTERVIEW · Seen Nov 2025
- Intersection of Two ListsONSITE INTERVIEW · Seen Jan 2025
- Maximum Subarray SumONSITE INTERVIEW · Seen Jan 2025
- Fibonacci NumberONSITE INTERVIEW · Seen Nov 2024
Similar questions at other companies
- Recover Coins from Change CountsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Coin Game From The EndsTekion · PHONE SCREENTekion interview questions
- Jump Game with Prime-3 StepsUber · OAUber interview questions
- Jump Game with Prime-3 StepsAgoda · OAAgoda interview questions
- Maximum-Product Subarray with an Empty ChoiceAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Plus OneDruva · ONSITE INTERVIEW
- Best Time to Buy and Sell StockKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
- Maximum Product of Three IntegersPelatro · ONSITE INTERVIEW
Interview reports that mention this question
JP Morgan Chase interview experiences
- JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
- JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
- JP Morgan Chase Data and AI Intern Superday: 11 Experiences
- JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
- JPMorgan Code for Good India: 10 Experiences (Part 4 of 5)