Positive integers up to N that are not present in given Array | Java 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
import java . io . * ; import java . util . * ; class GFG { static void findMissingNumbers ( int [ ] arr , int len ) { int M = 15 ; BitSet bset = new BitSet ( M ) ; for ( int i = 0 ; i < M ; i ++ ) { bset . set ( i ) ; } for ( int i = 0 ; i < len ; i ++ ) { bset . set ( arr [ i ] - 1 , false ) ; } for ( int i = bset . nextSetBit ( 0 ) ; i >= 0 ; i = bset . nextSetBit ( i + 1 ) ) { if ( i + 1 > len ) break ; System . out . println ( i + 1 ) ; } } public static void main ( String [ ] args ) { int [ ] arr = new int [ ] { 1 , 2 , 4 , 6 , 8 , 9 } ; int n = arr . length ; findMissingNumbers ( arr , n ) ; } }