create a visited array
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 ] -- ; }