Longest common anagram subsequence from N strings | c # program to find longest possible subsequence anagram of N strings . ; function to store frequency of each character in each string ; function to Find longest possible sequence of N strings which is anagram to each other ; to get lexicographical largest sequence . ; find minimum of that character ; print that character minimum number of times ; Driver code ; to store frequency of each character in each string ; to get frequency of each character ; function call
using System ; class GFG { public readonly int MAX_CHAR = 26 ; public static void frequency ( int [ , ] fre , string [ ] s , int n ) { for ( int i = 0 ; i < n ; i ++ ) { string str = s [ i ] ; for ( int j = 0 ; j < str . Length ; j ++ ) { fre [ i , str [ j ] - ' a ' ] ++ ; } } } public static void LongestSequence ( int [ , ] fre , int n ) { for ( int i = 24 ; i >= 0 ; i -- ) { int mi = fre [ 0 , i ] ; for ( int j = 1 ; j < n ; j ++ ) { mi = Math . Min ( fre [ j , i ] , mi ) ; } while ( mi -- != 0 ) { Console . Write ( ( char ) ( ' a ' + i ) ) ; } } } public static void Main ( string [ ] args ) { string [ ] s = new string [ ] { " loo " , " lol " , " olive " } ; int n = s . Length ; int [ , ] fre = new int [ n , 26 ] ; frequency ( fre , s , n ) ; LongestSequence ( fre , n ) ; } }