Longest common anagram subsequence from N strings | JavaScript 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
let MAX_CHAR = 26 ; function frequency ( fre , s , n ) { for ( let i = 0 ; i < n ; i ++ ) { let str = s [ i ] ; for ( let j = 0 ; j < str . length ; j ++ ) fre [ i ] [ str [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } } function LongestSequence ( fre , n ) { for ( let i = 24 ; i >= 0 ; i -- ) { let mi = fre [ 0 ] [ i ] ; for ( let j = 1 ; j < n ; j ++ ) mi = Math . min ( fre [ j ] [ i ] , mi ) ; while ( mi -- != 0 ) document . write ( String . fromCharCode ( ' ' . charCodeAt ( 0 ) + i ) ) ; } } let s = [ " " , " " , " " ] ; let n = s . length ; let fre = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { fre [ i ] = new Array ( 26 ) ; for ( let j = 0 ; j < 26 ; j ++ ) fre [ i ] [ j ] = 0 ; } frequency ( fre , s , n ) ; LongestSequence ( fre , n ) ;