Find missing elements of a range | A hashing 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 ] ; Insert all elements of arr [ ] in set ; Traverse throught the range an print all missing elements ; Driver program to test above function
import java . util . Arrays ; import java . util . HashSet ; public class Print { static void printMissing ( int ar [ ] , int low , int high ) { HashSet < Integer > hs = new HashSet < > ( ) ; for ( int i = 0 ; i < ar . length ; i ++ ) hs . add ( ar [ i ] ) ; for ( int i = low ; i <= high ; i ++ ) { if ( ! hs . contains ( i ) ) { System . out . print ( i + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 , 4 } ; int low = 1 , high = 10 ; printMissing ( arr , low , high ) ; } }