Longest subsequence with consecutive English alphabets | Function to find the length of subsequence starting with character ch ; Length of the string ; Stores the maximum length ; Traverse the given string ; If s [ i ] is required character ch ; Increment ans by 1 ; Increment character ch ; Return the current maximum length with character ch ; Function to find the maximum length of subsequence of consecutive characters ; Stores the maximum length of consecutive characters ; Update ans ; Return the maximum length of subsequence ; Driver Code ; Input ; Function Call
def findSubsequence ( S , ch ) : NEW_LINE INDENT N = len ( S ) NEW_LINE ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( S [ i ] == ch ) : NEW_LINE INDENT ans += 1 NEW_LINE ch = chr ( ord ( ch ) + 1 ) NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT def findMaxSubsequence ( S ) : NEW_LINE INDENT ans = 0 NEW_LINE for ch in range ( ord ( ' a ' ) , ord ( ' z ' ) + 1 ) : NEW_LINE INDENT ans = max ( ans , findSubsequence ( S , chr ( ch ) ) ) NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = " abcabefghijk " NEW_LINE print ( findMaxSubsequence ( S ) ) NEW_LINE DEDENT