text: Check if frequency of character in one string is a factor or multiple of frequency of same character in other string | C # implementation of the approach ; Function that checks if the frequency of character are a factor or multiple of each other ; map store frequency of each character ; if any frequency is 0 , then continue as condition is satisfied ; if factor or multiple , then condition satisfied ; if condition not satisfied ; Driver code
code: using System ; using System . Collections . Generic ; class GFG { public static Boolean multipleOrFactor ( String s1 , String s2 ) { Dictionary < char , int > m1 = new Dictionary < char , int > ( ) ; Dictionary < char , int > m2 = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < s1 . Length ; i ++ ) { if ( m1 . ContainsKey ( s1 [ i ] ) ) { var x = m1 [ s1 [ i ] ] ; m1 [ s1 [ i ] ] = ++ x ; } else m1 . Add ( s1 [ i ] , 1 ) ; } for ( int i = 0 ; i < s2 . Length ; i ++ ) { if ( m2 . ContainsKey ( s2 [ i ] ) ) { var x = m2 [ s2 [ i ] ] ; m2 [ s2 [ i ] ] = ++ x ; } else m2 . Add ( s2 [ i ] , 1 ) ; } foreach ( KeyValuePair < char , int > entry in m1 ) { if ( ! m2 . ContainsKey ( entry . Key ) ) continue ; if ( m2 [ entry . Key ] != 0 && ( m2 [ entry . Key ] % entry . Value == 0 entry . Value % m2 [ entry . Key ] == 0 ) ) continue ; else return false ; } return true ; } public static void Main ( String [ ] args ) { String s1 = " geeksforgeeks " , s2 = " geeks " ; if ( multipleOrFactor ( s1 , s2 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }