Minimum number of characters required to be added to a String such that all lowercase alphabets occurs as a subsequence in increasing order | Function to find the LCS of strings S and string T ; Base Case ; Already Calculated State ; If the characters are the same ; Otherwise ; Function to find the minimum number of characters that needs to be appended in the string to get all lowercase alphabets as a subsequences ; String containing all the characters ; Stores the result of overlapping subproblems ; Return the minimum characters required ; Driver Code
function LCS ( S , N , T , M , dp ) { if ( N == 0 M == 0 ) return 0 ; if ( dp [ N ] [ M ] != 0 ) return dp [ N ] [ M ] ; if ( S . charAt ( N - 1 ) == T . charAt ( M - 1 ) ) { return dp [ N ] [ M ] = 1 + LCS ( S , N - 1 , T , M - 1 , dp ) ; } return dp [ N ] [ M ] = Math . max ( LCS ( S , N - 1 , T , M , dp ) , LCS ( S , N , T , M - 1 , dp ) ) ; } function minimumCharacter ( S ) { var T = " " ; var N = S . length , M = T . length ; var dp = Array ( N + 1 ) . fill ( 0 ) . map ( x => Array ( M + 1 ) . fill ( 0 ) ) ; return ( 26 - LCS ( S , N , T , M , dp ) ) ; } var S = " " ; document . write ( minimumCharacter ( S ) ) ;