Most frequent word in first String which is not present in second String | C # implementation of above approach ; Function to return frequent word from S1 that isn 't  present in S2 ; create map of banned words ; find smallest and most frequent word ; check if word is not banned ; return answer ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static String smallestFreq ( String S1 , String S2 ) { Dictionary < String , int > banned = new Dictionary < String , int > ( ) ; for ( int i = 0 ; i < S2 . Length ; i ++ ) { String s = " " ; while ( i < S2 . Length && S2 [ i ] != ' ▁ ' ) s += S2 [ i ++ ] ; if ( banned . ContainsKey ( s ) ) { var val = banned [ s ] ; banned . Remove ( s ) ; banned . Add ( s , val + 1 ) ; } else { banned . Add ( s , 1 ) ; } } Dictionary < String , int > result = new Dictionary < String , int > ( ) ; String ans = " " ; int freq = 0 ; for ( int i = 0 ; i < S1 . Length ; i ++ ) { String s = " " ; while ( i < S1 . Length && S1 [ i ] != ' ▁ ' ) s += S1 [ i ++ ] ; if ( ! banned . ContainsKey ( s ) ) { if ( result . ContainsKey ( s ) ) { var val = result [ s ] ; result . Remove ( s ) ; result . Add ( s , val + 1 ) ; } else { result . Add ( s , 1 ) ; } if ( result [ s ] > freq || ( result [ s ] == freq && s . CompareTo ( ans ) < 0 ) ) { ans = s ; freq = result [ s ] ; } } } return ans ; } public static void Main ( String [ ] args ) { String S1 = " geeks ▁ for ▁ geeks ▁ is ▁ best ▁ place ▁ to ▁ learn " ; String S2 = " bad ▁ place " ; Console . WriteLine ( smallestFreq ( S1 , S2 ) ) ; } }