Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

21. Pascal's Triangle

EasyDay 6 of 60Arrays & Hashing

Given an integer numRows, return the first numRows rows of Pascal's triangle. Each row starts and ends with 1, and every inner number is the sum of the two numbers just above it in the previous row.

Example 1
Input: numRows = 5
Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
In row 4, the 6 comes from 3 + 3 in the row above.
Example 2
Input: numRows = 1
Output: [[1]]
Constraints
  • 1 <= numRows <= 30
Hints
Frequently asked at: Amazon, Apple, Adobe, TCS, Wipro
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min