Find missing elements of a range | Python library for binary search ; 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 . ; Driver code
from bisect import bisect_left NEW_LINE def printMissing ( arr , n , low , high ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE ptr = bisect_left ( arr , low ) NEW_LINE index = ptr NEW_LINE i = index NEW_LINE x = low NEW_LINE while ( i < n and x <= high ) : NEW_LINE INDENT if ( arr [ i ] != x ) : NEW_LINE INDENT print ( x , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT i = i + 1 NEW_LINE DEDENT x = x + 1 NEW_LINE DEDENT while ( x <= high ) : NEW_LINE INDENT print ( x , end = " ▁ " ) NEW_LINE x = x + 1 NEW_LINE DEDENT DEDENT arr = [ 1 , 3 , 5 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE low = 1 NEW_LINE high = 10 NEW_LINE printMissing ( arr , n , low , high ) ; NEW_LINE