text: Longest subsequence with at least one character appearing in every string | C # implementation of the approach ; Function to return the length of the longest sub - sequence with at least one common character in every string ; count [ 0 ] will store the number of strings which contain ' a ' , count [ 1 ] will store the number of strings which contain ' b ' and so on . . ; For every string ; Hash array to set which character is present in the current string ; If current character appears in the string then update its count ; Driver code
code: using System ; class GFG { static int MAX = 26 ; static int largestSubSeq ( string [ ] arr , int n ) { int [ ] count = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { string str = arr [ i ] ; bool [ ] hash = new bool [ MAX ] ; for ( int j = 0 ; j < str . Length ; j ++ ) { hash [ str [ j ] - ' a ' ] = true ; } for ( int j = 0 ; j < MAX ; j ++ ) { if ( hash [ j ] ) count [ j ] ++ ; } } int max = - 1 ; for ( int i = 0 ; i < MAX ; i ++ ) { if ( max < count [ i ] ) max = count [ i ] ; } return max ; } public static void Main ( ) { string [ ] arr = { " ab " , " bc " , " de " } ; int n = arr . Length ; Console . WriteLine ( largestSubSeq ( arr , n ) ) ; } }