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
def LIIDS ( arr , N ) : NEW_LINE INDENT dp = [ ] NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT dp . append ( 1 ) NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT j = i + i NEW_LINE while j <= N : NEW_LINE INDENT if j < N and i < N and arr [ j ] > arr [ i ] : NEW_LINE INDENT dp [ j ] = max ( dp [ j ] , dp [ i ] + 1 ) NEW_LINE DEDENT j += i NEW_LINE DEDENT if i < N : NEW_LINE INDENT ans = max ( ans , dp [ i ] ) NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 7 , 9 , 10 ] NEW_LINE N = len ( arr ) NEW_LINE print ( LIIDS ( arr , N ) ) NEW_LINE