Length of longest common subsequence containing vowels | C # implementation to find the length of longest common subsequence which contains all vowel characters ; function to check whether ' ch ' is a vowel or not ; Utility max ; function to find the length of longest common subsequence which contains all vowel characters ; Following steps build L [ m + 1 , n + 1 ] in bottom up fashion . Note that L [ i , j ] contains length of LCS of X [ 0. . i - 1 ] and Y [ 0. . j - 1 ] ; L [ m , n ] contains length of LCS for X [ 0. . n - 1 ] and Y [ 0. . m - 1 ] which contains all vowel characters ; Driver Code
using System ; class GFG { static int isVowel ( char ch ) { if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) return 1 ; return 0 ; } static int max ( int a , int b ) { return ( a > b ) ? a : b ; } static int lcs ( String X , String Y , int m , int n ) { int [ , ] L = new int [ m + 1 , n + 1 ] ; int i , j ; for ( i = 0 ; i <= m ; i ++ ) { for ( j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i , j ] = 0 ; else if ( ( X [ i - 1 ] == Y [ j - 1 ] ) && isVowel ( X [ i - 1 ] ) == 1 ) L [ i , j ] = L [ i - 1 , j - 1 ] + 1 ; else L [ i , j ] = max ( L [ i - 1 , j ] , L [ i , j - 1 ] ) ; } } return L [ m , n ] ; } static public void Main ( String [ ] args ) { String X = " aieef " ; String Y = " klaief " ; int m = X . Length ; int n = Y . Length ; Console . WriteLine ( " Length ▁ of ▁ LCS ▁ = ▁ " + lcs ( X , Y , m , n ) ) ; } }