text: Minimize the length of string by removing occurrence of only one character | C # program to minimize the length of string by removing occurrence of only one character ; Function to find the minimum length ; Count the frequency of each alphabet ; Find the alphabets with maximum frequency ; Subtract the frequency of character from length of string ; Driver Code
code: using System ; class GFG { static int minimumLength ( String s ) { int maxOcc = 0 , n = s . Length ; int [ ] arr = new int [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ s [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) if ( arr [ i ] > maxOcc ) maxOcc = arr [ i ] ; return ( n - maxOcc ) ; } public static void Main ( String [ ] args ) { String str = " afddewqd " ; Console . WriteLine ( minimumLength ( str ) ) ; } }