• 0

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