Find first k natural numbers missing in given array | Program to print first k missing number ; creating a hashmap ; Iterate over array ; Iterate to find missing element ; Driver Code
def printmissingk ( arr , n , k ) : NEW_LINE INDENT d = { } NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT d [ arr [ i ] ] = arr [ i ] NEW_LINE DEDENT cnt = 1 NEW_LINE fl = 0 NEW_LINE for i in range ( n + k ) : NEW_LINE INDENT if cnt not in d : NEW_LINE INDENT fl += 1 NEW_LINE print ( cnt , end = " ▁ " ) NEW_LINE if fl == k : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT cnt += 1 NEW_LINE DEDENT print ( ) NEW_LINE DEDENT arr = [ 1 , 4 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE k = 3 NEW_LINE printmissingk ( arr , n , k ) NEW_LINE