Sum of frequencies of characters of a string present in another string | C # program for the above approach ; Function to find sum of frequencies of characters of S1 present in S2 ; Insert all characters of string S1 in the set ; Traverse the string S2 ; Check if X is present in bset or not ; Increment count by 1 ; Finally , print the count ; Driver code ; Given strings
using System ; using System . Collections . Generic ; class GFG { static void countTotalFrequencies ( string S1 , string S2 ) { HashSet < char > bset = new HashSet < char > ( ) ; foreach ( char x in S1 ) bset . Add ( x ) ; int count = 0 ; foreach ( char x in S2 ) { if ( bset . Contains ( x ) ) count += 1 ; } Console . Write ( count ) ; } static void Main ( ) { string S1 = " geEksFOR " ; string S2 = " GeEksforgeEKS " ; countTotalFrequencies ( S1 , S2 ) ; } }