text: Minimum sum possible by removing all occurrences of any array element | C # program for the above approach ; Function to find minimum sum after deletion ; Stores frequency of array elements ; Traverse the array ; Calculate sum ; Update frequency of the current element ; Stores the minimum sum required ; Traverse map ; Find the minimum sum obtained ; Return minimum sum ; Driver code ; Input array ; Size of array
code: using System ; using System . Collections . Generic ; public class GFG { static int minSum ( int [ ] A , int N ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += A [ i ] ; if ( mp . ContainsKey ( A [ i ] ) ) { mp [ A [ i ] ] = mp [ A [ i ] ] + 1 ; } else { mp . Add ( A [ i ] , 1 ) ; } } int minSum = int . MaxValue ; foreach ( KeyValuePair < int , int > it in mp ) { minSum = Math . Min ( minSum , sum - ( it . Key * it . Value ) ) ; } return minSum ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 5 , 6 , 6 } ; int N = arr . Length ; Console . Write ( minSum ( arr , N ) + " STRNEWLINE " ) ; } }