Positive integers up to N that are not present in given Array | CPP program for the above approach ; Function to find positive integers from 1 to N that are not present in the array ; Declare bitset ; Iterate from 0 to M - 1 ; Iterate from 0 to len - 1 ; Iterate from bset . _Find_first ( ) to bset . size ( ) - 1 ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findMissingNumbers ( int arr [ ] , int len ) { const int M = 15 ; bitset < M > bset ; for ( int i = 0 ; i < M ; i ++ ) { bset . set ( i ) ; } for ( int i = 0 ; i < len ; i ++ ) { bset . set ( arr [ i ] - 1 , 0 ) ; } for ( int i = bset . _Find_first ( ) ; i < bset . size ( ) ; i = bset . _Find_next ( i ) ) { if ( i + 1 > len ) break ; cout << i + 1 << endl ; } } int main ( ) { int arr [ ] = { 1 , 2 , 4 , 6 , 8 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findMissingNumbers ( arr , n ) ; return 0 ; }