Smallest missing non | Function to prthe smallest missing non - negative integer up to every array indices ; Stores the smallest missing non - negative integers between start index to current index ; Store the boolean value to check smNonNeg present between start index to each index of the array ; Traverse the array ; Since output always lies in the range [ 0 , N - 1 ] ; Check if smNonNeg is present between start index and current index or not ; Print smallest missing non - negative integer ; Driver Code
def smlstNonNeg ( arr , N ) : NEW_LINE INDENT smNonNeg = 0 NEW_LINE hash = [ 0 ] * ( N + 1 ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] >= 0 and arr [ i ] < N ) : NEW_LINE INDENT hash [ arr [ i ] ] = True NEW_LINE DEDENT while ( hash [ smNonNeg ] ) : NEW_LINE INDENT smNonNeg += 1 NEW_LINE DEDENT print ( smNonNeg , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 0 , 1 , 2 , 3 , 5 ] NEW_LINE N = len ( arr ) NEW_LINE smlstNonNeg ( arr , N ) NEW_LINE DEDENT