-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathActivitySelectionProblem.java
More file actions
51 lines (42 loc) · 915 Bytes
/
ActivitySelectionProblem.java
File metadata and controls
51 lines (42 loc) · 915 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Meeting
{
int start;
int end;
Meeting(int start , int end)
{
this.start=start;
this.end=end;
}
}
class MComparator implements Comparator<Meeting>
{
public int compare(Meeting a , Meeting b)
{
return a.end - b.end;
}
}
class Solution
{
public static int activitySelection(int start[], int end[], int n)
{
// add your code here
ArrayList<Meeting> list=new ArrayList<>();
for(int i=0;i<n;i++)
{
list.add(new Meeting(start[i], end[i]));
}
MComparator m=new MComparator();
Collections.sort(list , m);
int count=1;
int limit=list.get(0).end;
for(int i=1;i<n;i++)
{
if(list.get(i).start >limit)
{
count++;
limit=list.get(i).end;
}
}
return count;
}
}