Largest increasing subsequence of consecutive integers | Python3 implementation of longest continuous increasing subsequence Function for LIS ; Initialize result ; iterate through array and find end index of LIS and its Size ; print LIS size ; print LIS after setting start element ; Driver Code
def findLIS ( A , n ) : NEW_LINE INDENT hash = dict ( ) NEW_LINE LIS_size , LIS_index = 1 , 0 NEW_LINE hash [ A [ 0 ] ] = 1 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if A [ i ] - 1 not in hash : NEW_LINE INDENT hash [ A [ i ] - 1 ] = 0 NEW_LINE DEDENT hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1 NEW_LINE if LIS_size < hash [ A [ i ] ] : NEW_LINE INDENT LIS_size = hash [ A [ i ] ] NEW_LINE LIS_index = A [ i ] NEW_LINE DEDENT DEDENT print ( " LIS _ size ▁ = " , LIS_size ) NEW_LINE print ( " LIS ▁ : ▁ " , end = " " ) NEW_LINE start = LIS_index - LIS_size + 1 NEW_LINE while start <= LIS_index : NEW_LINE INDENT print ( start , end = " ▁ " ) NEW_LINE start += 1 NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ 2 , 5 , 3 , 7 , 4 , 8 , 5 , 13 , 6 ] NEW_LINE n = len ( A ) NEW_LINE findLIS ( A , n ) NEW_LINE DEDENT