Find least non | Javascript program to find the least non - overlapping number from a given set intervals ; function to find the smallest non - overlapping number ; create a visited array ; find the first missing value ; Driver function
var MAX = 100005 ; function find_missing ( interval ) { var vis = Array ( MAX ) . fill ( 0 ) ; for ( var i = 0 ; i < interval . length ; ++ i ) { var start = interval [ i ] [ 0 ] ; var end = interval [ i ] [ 1 ] ; vis [ start ] ++ ; vis [ end + 1 ] -- ; } for ( var i = 1 ; i < MAX ; i ++ ) { vis [ i ] += vis [ i - 1 ] ; if ( ! vis [ i ] ) { document . write ( i + " " ) ; return ; } } } var interval = [ [ 0 , 14 ] , [ 86 , 108 ] , [ 22 , 30 ] , [ 5 , 17 ] ] ; find_missing ( interval ) ;