Find all missing numbers from a given sorted array | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printMissingElements ( int arr [ ] , int N ) { int b [ arr [ N - 1 ] + 1 ] = { 0 } ; 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 ) { cout << i << " ▁ " ; } } } int main ( ) { int arr [ ] = { 6 , 7 , 10 , 11 , 13 } ; int N = sizeof ( arr ) / sizeof ( int ) ; printMissingElements ( arr , N ) ; return 0 ; }