Find the interval which contains maximum number of concurrent meetings | Function to find time slot of maximum concurrent meeting ; Sort array by start time of meeting ; Declare Minheap ; Insert first meeting end time ; Initialize max_len , max_start and max_end ; Traverse over sorted array to find required slot ; Pop all meetings that end before current meeting ; Push current meeting end time ; Update max_len , max_start and max_end if size of queue is greater than max_len ; Print slot of maximum concurrent meeting ; Given array of meetings ; Function Call
function maxConcurrentMeetingSlot ( meetings ) { meetings . sort ( function ( a , b ) { return ( a [ 0 ] != b [ 0 ] ) ? a [ 0 ] - b [ 0 ] : a [ 1 ] - b [ 1 ] } ) ; let pq = [ ] ; pq . push ( meetings [ 0 ] [ 1 ] ) ; pq . sort ( function ( a , b ) { return a - b ; } ) ; let max_len = 0 , max_start = 0 ; let max_end = 0 ; for ( let k = 0 ; k < meetings . length ; k ++ ) { while ( pq . length != 0 && meetings [ k ] [ 0 ] >= pq [ 0 ] ) pq . shift ( ) ; pq . push ( meetings [ k ] [ 1 ] ) ; pq . sort ( function ( a , b ) { return a - b ; } ) ; if ( pq . length > max_len ) { max_len = pq . length ; max_start = meetings [ k ] [ 0 ] ; max_end = pq [ 0 ] ; } } document . write ( max_start + " " + max_end + " " ) ; } let meetings = [ [ 100 , 200 ] , [ 50 , 300 ] , [ 300 , 400 ] ] ; maxConcurrentMeetingSlot ( meetings ) ;