Minimize sum of given array by removing all occurrences of a single digit | Function to remove each digit from the given integer ; Convert into string ; Stores final string ; Traverse the string ; Append it to the final string ; Return integer value ; Function to find the minimum sum by removing occurences of each digit ; Iterate in range [ 0 , 9 ] ; Traverse the array ; Update the minimum sum ; Print the minimized sum ; Driver Code
using System ; public class GFG { static int remove ( int N , int digit ) { String strN = N . ToString ( ) ; String ans = " " ; foreach ( char i in strN . ToCharArray ( ) ) { if ( ( i - '0' ) == digit ) { continue ; } ans += i ; } return Int32 . Parse ( ans ) ; } static void getMin ( int [ ] arr ) { int minSum = Int32 . MaxValue ; for ( int i = 0 ; i < 10 ; i ++ ) { int curSum = 0 ; foreach ( int num in arr ) curSum += remove ( num , i ) ; minSum = Math . Min ( minSum , curSum ) ; } Console . WriteLine ( minSum ) ; } static public void Main ( ) { int [ ] arr = { 34 , 23 , 85 , 93 } ; getMin ( arr ) ; } }