Maximum product of an increasing subsequence | JavaScript program implementation ; Returns product of maximum product increasing subsequence . ; Initialize MPIS values ; Compute optimized MPIS values considering every element as ending element of sequence ; Pick maximum of all product values using for loop ; Driver Code
of maximum product of an increasing function lis ( arr , n ) { let mpis = [ ] ; let max = Number . MIN_VALUE ; for ( let i = 0 ; i < n ; i ++ ) mpis [ i ] = arr [ i ] ; for ( let i = 1 ; i < n ; i ++ ) for ( let j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ; for ( let k = 0 ; k < mpis . length ; k ++ ) { if ( mpis [ k ] > max ) { max = mpis [ k ] ; } } return max ; } let arr = [ 3 , 100 , 4 , 5 , 150 , 6 ] ; let n = arr . length ; document . write ( lis ( arr , n ) ) ;