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 ; Input ; Function Call
function findSubsequence ( S , ch ) { let N = S . length ; let ans = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ch ) { ans ++ ; ch = String . fromCharCode ( ch . charCodeAt ( 0 ) + 1 ) ; } } return ans ; } function findMaxSubsequence ( S ) { let ans = 0 ; for ( let ch = ' ' . charCodeAt ( 0 ) ; ch <= ' ' . charCodeAt ( 0 ) ; ch ++ ) { ans = Math . max ( ans , findSubsequence ( S , String . fromCharCode ( ch ) ) ) ; } return ans ; } let S = " " ; document . write ( findMaxSubsequence ( S ) ) ;