Length of longest increasing index dividing subsequence | Function to find the length of the longest increasing sub - sequence such that the index of the element is divisible by index of previous element ; Initialize the dp [ ] array with 1 as a single element will be of 1 length ; Traverse the given array ; If the index is divisible by the previous index ; If increasing subsequence identified ; Longest length is stored ; Driver code
function LIIDS ( arr , N ) { let dp = [ ] ; let ans = 0 ; for ( let i = 1 ; i <= N ; i ++ ) { dp [ i ] = 1 ; } for ( let i = 1 ; i <= N ; i ++ ) { for ( let j = i + i ; j <= N ; j += i ) { if ( j < arr . length && arr [ j ] > arr [ i ] ) { dp [ j ] = Math . max ( dp [ j ] , dp [ i ] + 1 ) ; } } ans = Math . max ( ans , dp [ i ] ) ; } return ans ; } let arr = [ 1 , 2 , 3 , 7 , 9 , 10 ] ; let N = arr . length ; document . write ( LIIDS ( arr , N ) ) ;