Finding maximum ending time
let maxb = 0 ; for ( let i = 0 ; i < end . length ; i ++ ) { maxb = Math . max ( maxb , end [ i ] ) ; } let maxc = Math . max ( maxa , maxb ) ; let x = new Array ( maxc + 2 ) ; x . fill ( 0 ) ; let cur = 0 , idx = 0 ;