Make all array elements equal to 0 by replacing minimum subsequences consisting of equal elements | Function to find minimum count of operations required to convert all array elements to zero by replacing subsequence of equal elements to 0 ; Store distinct elements present in the array ; Traverse the array ; If arr [ i ] is already present in the Set or arr [ i ] is equal to 0 ; Otherwise , increment ans by 1 and insert current element ; Given array ; Size of the given array
def minOpsToTurnArrToZero ( arr , N ) : NEW_LINE INDENT st = dict ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( i in st . keys ( ) or arr [ i ] == 0 ) : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT st [ arr [ i ] ] = 1 NEW_LINE DEDENT DEDENT print ( len ( st ) ) NEW_LINE DEDENT arr = [ 3 , 7 , 3 ] NEW_LINE N = len ( arr ) NEW_LINE minOpsToTurnArrToZero ( arr , N ) NEW_LINE