Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Pascals triangle javascript code

Problem :

Create a pascal’s triangle using javascript. More details about Pascal’s triangle pattern can be found here.

Input:

#Rows = 6

Output:

Pascal's_triangle

Logic :

  • Pascal’s triangle can be simulated using 2-D array
  • While creating 2-D array
  • If the element is the either first or last element then initialize it with 1
  • Else initialize it with the sum of the elements from previous row

Time complexity : O (n^2)

Solution :

 

PascalTriangle-min


 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *