-
Notifications
You must be signed in to change notification settings - Fork 101
/
MeetingScheduler.java
107 lines (91 loc) · 2.23 KB
/
MeetingScheduler.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* Problem Statement-
* ------------------------------
* There are lot of meeting which has been schedule for today and schedule of meetings has been provide based on that you need to arrange minimum rooms so that nobody has to wait for meeting room as cost of meeting room is also high, so arrange less meeting room for all the meetings.
input--> (startTime,endTime)
(1,4),(2,8),(3,6)
output- 3
input--> (1,5),(2,6),(6,8),(7,9)
output-> 2
*/
package com.javaaid.ip.app_dynamics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
/**
*
* @author Kanahaiya Gupta
*
*/
class Time {
private int inTime;
private int outTime;
public Time(int inTime, int outTime) {
super();
this.inTime = inTime;
this.outTime = outTime;
}
public int getInTime() {
return inTime;
}
public void setInTime(int inTime) {
this.inTime = inTime;
}
public int getOutTime() {
return outTime;
}
public void setOutTime(int outTime) {
this.outTime = outTime;
}
}
public class MeetingScheduler {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
List<Time> lists = new ArrayList<Time>();
while (T-- > 0) {
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int in = sc.nextInt();
int out = sc.nextInt();
Time slot = new Time(in, out);
lists.add(slot);
}
int minRoomCount = getMinRoomCount(lists);
System.out.println(minRoomCount);
}
}
private static int getMinRoomCount(List<Time> lists) {
int a[] = new int[25];
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Time t : lists) {
map.put(t.getOutTime(), -1);
}
for (Time interval : lists) {
fillArray(interval, map, a);
}
int max = getMax(a);
return max;
}
private static int getMax(int[] a) {
int max = Integer.MIN_VALUE;
for (int i = 0; i < a.length; i++) {
max = Math.max(max, a[i]);
}
return max;
}
private static void fillArray(Time interval, HashMap<Integer, Integer> map, int[] a) {
int start = interval.getInTime();
int end = interval.getOutTime();
int i = 0;
if (map.containsKey(start)) {
i = start+1;
} else {
i = start;
}
for (; i <= end; i++) {
a[i]++;
}
}
}