text: Remove even frequency characters from the string | C # implementation of the approach ; Function that removes the characters which have even frequencies in the string ; create a map to store the frequency of each character ; to store the new string ; remove the characters which have even frequencies ; if the character has even frequency then skip ; else concatenate the character to the new string ; display the modified string ; Driver code ; remove the characters which have even frequencies
code: using System ; using System . Collections . Generic ; class GFG { static void solve ( String s ) { Dictionary < char , int > m = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( m . ContainsKey ( s [ i ] ) ) { var val = m [ s [ i ] ] ; m . Remove ( s [ i ] ) ; m . Add ( s [ i ] , val + 1 ) ; } else m . Add ( s [ i ] , 1 ) ; } String new_string = " " ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( m [ s [ i ] ] % 2 == 0 ) continue ; new_string = new_string + s [ i ] ; } Console . WriteLine ( new_string ) ; } public static void Main ( String [ ] args ) { String s = " aabbbddeeecc " ; solve ( s ) ; } }