Find all numbers in range [ 1 , N ] that are not present in given Array | C ++ program for above approach ; Function to find the missing numbers ; traverse the array arr [ ] ; Update ; Traverse the array arr [ ] ; If Num is not present ; Driver Code ; Given Input ; Function Call
#include <iostream> NEW_LINE using namespace std ; void getMissingNumbers ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { arr [ abs ( arr [ i ] ) - 1 ] = - ( abs ( arr [ abs ( arr [ i ] ) - 1 ] ) ) ; } for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] > 0 ) cout << i + 1 << " ▁ " ; } } int main ( ) { int N = 5 ; int arr [ ] = { 5 , 5 , 4 , 4 , 2 } ; getMissingNumbers ( arr , N ) ; return 0 ; }