forked from architsingla13/InterviewBit-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotelBookings.java
More file actions
32 lines (28 loc) · 730 Bytes
/
HotelBookings.java
File metadata and controls
32 lines (28 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package Array;
import java.util.*;
/**
* Author - archit.s
* Date - 27/08/18
* Time - 1:44 PM
*/
public class HotelBookings {
public boolean hotel(ArrayList<Integer> arrive, ArrayList<Integer> depart, int K) {
Collections.sort(arrive);
Collections.sort(depart);
int roomsRequired=1,i=1,j=0;
int max= 1;
while(i<arrive.size() && j<arrive.size() ){
if(arrive.get(i)<depart.get(j) ){
i++;
roomsRequired++;
if(roomsRequired > max){
max = roomsRequired;
}
}else{
j++;
roomsRequired--;
}
}
return max <= K;
}
}