Find least non | Function to find the smallest non - overlapping number ; Sort the intervals based on their starting value ; Check if any missing value exist ; Finally print the missing value ; Driver code
function findMissing ( interval ) { interval . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] ; } ) ; let mx = 0 ; for ( let i = 0 ; i < interval . length ; ++ i ) { if ( interval [ i ] [ 0 ] > mx ) { document . write ( mx + " " ) ; return ; } else mx = Math . max ( mx , interval [ i ] [ 1 ] + 1 ) ; } document . write ( mx ) ; } let interval = [ [ 0 , 14 ] , [ 86 , 108 ] , [ 22 , 30 ] , [ 5 , 17 ] ] ; findMissing ( interval ) ;