27/180: GeeksForGeeks : Find the point where maximum intervals overlap.

Event Type         Interval        Number of Guests
Arrival 1 1
Arrival 2 2
Exit 4 1
Arrival 5 2
Arrival 5 3
Exit 5 2
Exit 9 1
Arrival 10 2
Exit 12 1
Exit 12 0
public static void getMaximumGuest(int[] arrival, int[] exit, int n){
Arrays.sort(arrival);
Arrays.sort(arrival);
int i = 1, j = 0;
int curr_guests = 1; int max_guest = 1;
int time_interval = arrival[i];
while(i < n && j < n){
if(arrival[i] <= exit[j]){
curr_guests++;
if(max_guest < curr_guests)
{
max_guest = curr_guests;
time_interval = arrival[i];
}
i++;
}else{
curr_guests--;
j++;
}

}
System.out.println("Maximum no. of guests = "+ max_guest + " at time " + time_interval);
}

--

--

--

I am Indian by birth, Punjabi by destiny. Humanity is my religion. Love to eat, travel, read books and my million dreams keep me alive.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Enabling iOS Splash Screens for Progressive Web Apps

FAQs about Ember.js in 2019

Spring- Dependency injection

Using Intersection Observer for updating page navigation and history.

Build a Chat system using Rails 5 API Action Cable and ReactJS with multiple private rooms and…

Create a Halo 5 Inspired Loading Icon With HTML/CSS and Vanilla Javascript

3 React concepts I wish I knew when I started

How to Start Nodejs Development After Installation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Navneet Ojha

Navneet Ojha

I am Indian by birth, Punjabi by destiny. Humanity is my religion. Love to eat, travel, read books and my million dreams keep me alive.

More from Medium

Autowiring in Spring

First Phase — Introduce yourself

My experience with milestone based learning.

A variable is an important and ubiquitous concept in programming.