FastPrepPascal's Triangle
Problems/Pascal's Triangle

Pascal's Triangle

JP Morgan Chase logoJP Morgan Chase● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a JP Morgan Chase new grad onsite interview. The report names Pascal's triangle without saying whether it wants one row or the full triangle. This exercise returns the first requested number of rows, and sets the rule for zero rows and a limit. Our version is about 85% the same as the reported question.

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

  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)

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)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public int[][] generateTriangle(int numRows) {
        // Write your code here.
    }
}
Checking account…