Longest dividing subsequence | lds ( ) returns the length of the longest dividing subsequence in arr [ ] of size n ; Compute optimized lds values in bottom up manner ; Return maximum value in lds [ ] ; Driver program to test above function
function lds ( arr , n ) { let lds = new Array ( n ) ; lds [ 0 ] = 1 ; for ( let i = 1 ; i < n ; i ++ ) { lds [ i ] = 1 ; for ( let j = 0 ; j < i ; j ++ ) if ( lds [ j ] != 0 && arr [ i ] % arr [ j ] == 0 ) lds [ i ] = Math . max ( lds [ i ] , lds [ j ] + 1 ) ; } let max = Math . max ( ... lds ) ; return max ; } let arr = [ 2 , 11 , 16 , 12 , 36 , 60 , 71 , 17 , 29 , 144 , 288 , 129 , 432 , 993 ] ; let n = arr . length ; document . write ( " " + lds ( arr , n ) ) ;