Remove all occurrences of any element for maximum array sum | Python3 program to convert fractional decimal to binary number ; Find total sum and frequencies of elements ; Find minimum value to be subtracted . ; Find maximum sum after removal ; Driver Code
from sys import maxsize NEW_LINE def maxSumArray ( arr , n ) : NEW_LINE INDENT sum1 = 0 NEW_LINE mp = { i : 0 for i in range ( 4 ) } NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum1 += arr [ i ] NEW_LINE mp [ arr [ i ] ] += 1 NEW_LINE DEDENT minimum = maxsize NEW_LINE for key , value in mp . items ( ) : NEW_LINE INDENT if ( key == 0 ) : NEW_LINE INDENT continue NEW_LINE DEDENT minimum = min ( minimum , value * key ) NEW_LINE DEDENT return ( sum1 - minimum ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 1 , 3 , 3 , 2 , 2 , 1 , 1 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maxSumArray ( arr , n ) ) NEW_LINE DEDENT