text: Maximum height of triangular arrangement of array values | Javascript program to find the maximum height of Pyramidal Arrangement of array values ; Just checking whether ith level is possible or not if possible then we must have atleast ( i * ( i + 1 ) ) / 2 elements in the array ; updating the result value each time ; otherwise we have exceeded n value ; Driver Code
code: function MaximumHeight ( a , n ) { let result = 1 ; for ( i = 1 ; i <= n ; ++ i ) { let y = ( i * ( i + 1 ) ) / 2 ; if ( y < n ) result = i ; else break ; } return result ; } let arr = [ 40 , 100 , 20 , 30 ] ; let n = arr . length ; document . write ( MaximumHeight ( arr , n ) ) ;