Find all missing numbers from a given sorted array | Java program for the above approach ; Function to find the missing elements ; Initialize an array with zero of size equals to the maximum element in the array ; Make b [ i ] = 1 if i is present in the array ; If the element is present make b [ arr [ i ] ] = 1 ; Print the indices where b [ i ] = 0 ; Driver Code ; Given array arr [ ] ; Function call
import java . util . * ; class GFG { static void printMissingElements ( int arr [ ] , int N ) { int [ ] b = new int [ arr [ N - 1 ] + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { b [ arr [ i ] ] = 1 ; } for ( int i = arr [ 0 ] ; i <= arr [ N - 1 ] ; i ++ ) { if ( b [ i ] == 0 ) { System . out . print ( i + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 7 , 10 , 11 , 13 } ; int N = arr . length ; printMissingElements ( arr , N ) ; } }