Find the interval which contains maximum number of concurrent meetings | Java implementation of the above approach ; 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 ; Driver Code ; Given array of meetings ; Function Call
import java . util . * ; import java . lang . * ; class GFG { static void maxConcurrentMeetingSlot ( int [ ] [ ] meetings ) { Arrays . sort ( meetings , ( a , b ) -> ( a [ 0 ] != b [ 0 ] ) ? a [ 0 ] - b [ 0 ] : a [ 1 ] - b [ 1 ] ) ; PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ; pq . add ( meetings [ 0 ] [ 1 ] ) ; int max_len = 0 , max_start = 0 ; int max_end = 0 ; for ( int [ ] k : meetings ) { while ( ! pq . isEmpty ( ) && k [ 0 ] >= pq . peek ( ) ) pq . poll ( ) ; pq . add ( k [ 1 ] ) ; if ( pq . size ( ) > max_len ) { max_len = pq . size ( ) ; max_start = k [ 0 ] ; max_end = pq . peek ( ) ; } } System . out . println ( max_start + " ▁ " + max_end ) ; } public static void main ( String [ ] args ) { int meetings [ ] [ ] = { { 100 , 200 } , { 50 , 300 } , { 300 , 400 } } ; maxConcurrentMeetingSlot ( meetings ) ; } }