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
def remove ( N , digit ) : NEW_LINE INDENT strN = str ( N ) NEW_LINE ans = ' ' NEW_LINE for i in strN : NEW_LINE INDENT if int ( i ) == digit : NEW_LINE INDENT continue NEW_LINE DEDENT ans += i NEW_LINE DEDENT return int ( ans ) NEW_LINE DEDENT def getMin ( arr ) : NEW_LINE INDENT minSum = float ( ' inf ' ) NEW_LINE for i in range ( 10 ) : NEW_LINE INDENT curSum = 0 NEW_LINE for num in arr : NEW_LINE INDENT curSum += remove ( num , i ) NEW_LINE DEDENT minSum = min ( minSum , curSum ) NEW_LINE DEDENT print ( minSum ) NEW_LINE DEDENT arr = [ 34 , 23 , 85 , 93 ] NEW_LINE getMin ( arr ) NEW_LINE