Minimum number of distinct elements after removing m items | Function to find distintc id 's ; Store the occurrence of ids ; Store into the list value as key and vice - versa ; Start removing elements from the beginning ; Remove if current value is less than or equal to mi ; Return the remaining size ; Driver code
def distinctIds ( arr , n , mi ) : NEW_LINE INDENT m = { } NEW_LINE v = [ ] NEW_LINE count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if arr [ i ] in m : NEW_LINE m [ arr [ i ] ] += 1 NEW_LINE else : NEW_LINE m [ arr [ i ] ] = 1 NEW_LINE DEDENT for i in m : NEW_LINE INDENT v . append ( [ m [ i ] , i ] ) NEW_LINE DEDENT v . sort ( ) NEW_LINE size = len ( v ) NEW_LINE for i in range ( size ) : NEW_LINE INDENT if ( v [ i ] [ 0 ] <= mi ) : NEW_LINE mi -= v [ i ] [ 0 ] NEW_LINE count += 1 NEW_LINE else : NEW_LINE return size - count NEW_LINE DEDENT return size - count NEW_LINE DEDENT arr = [ 2 , 3 , 1 , 2 , 3 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE m = 3 NEW_LINE print ( distinctIds ( arr , n , m ) ) NEW_LINE