Smallest missing non | Function to prlet the 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
function smlstNonNeg ( arr , N ) { let smNonNeg = 0 ; let hash = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { hash [ i ] = false ; } for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= 0 && arr [ i ] < N ) { hash [ arr [ i ] ] = true ; } while ( hash [ smNonNeg ] ) { smNonNeg ++ ; } document . write ( smNonNeg + " " ) ; } } let arr = [ 0 , 1 , 2 , 3 , 5 ] ; let N = arr . length ; smlstNonNeg ( arr , N ) ;