text: Find missing elements of a range | A sorting based Java program to find missing elements from an array ; Print all elements of range [ low , high ] that are not present in arr [ 0. . n - 1 ] ; Do binary search for ' low ' in sorted array and find index of first element which either equal to or greater than low . ; Start from the found index and linearly search every range element x after this index in arr [ ] ; If x doesn 't math with current  element print it ; If x matches , move to next element in arr [ ] ; Move to next element in range [ low , high ] ; Print range elements thar are greater than the last element of sorted array . ; Utility function to find ceil index of given element ; Driver Code
code: using System ; class GFG { static void printMissing ( int [ ] ar , int low , int high ) { Array . Sort ( ar ) ; int index = ceilindex ( ar , low , 0 , ar . Length - 1 ) ; int x = low ; while ( index < ar . Length && x <= high ) { if ( ar [ index ] != x ) { Console . Write ( x + " ▁ " ) ; } else index ++ ; x ++ ; } while ( x <= high ) { Console . Write ( x + " ▁ " ) ; x ++ ; } } static int ceilindex ( int [ ] ar , int val , int low , int high ) { if ( val < ar [ 0 ] ) return 0 ; if ( val > ar [ ar . Length - 1 ] ) return ar . Length ; int mid = ( low + high ) / 2 ; if ( ar [ mid ] == val ) return mid ; if ( ar [ mid ] < val ) { if ( mid + 1 < high && ar [ mid + 1 ] >= val ) return mid + 1 ; return ceilindex ( ar , val , mid + 1 , high ) ; } else { if ( mid - 1 >= low && ar [ mid - 1 ] < val ) return mid ; return ceilindex ( ar , val , low , mid - 1 ) ; } } static public void Main ( ) { int [ ] arr = { 1 , 3 , 5 , 4 } ; int low = 1 , high = 10 ; printMissing ( arr , low , high ) ; } }