Pascals triangle javascript code

Problem :

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


#Rows = 6



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 :




You may also like...

Leave a Reply

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