-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion7.java
More file actions
30 lines (26 loc) · 1.04 KB
/
Copy pathQuestion7.java
File metadata and controls
30 lines (26 loc) · 1.04 KB
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
package practice4_sort;
import java.util.ArrayList;
public class Question7 {
public int solution(int[][] meetings){
ArrayList<int[]> list = new ArrayList<>();
for(int[] x : meetings){
list.add(new int[]{x[0], 1});
list.add(new int[]{x[1], 2});
}
list.sort((a, b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);
int answer = 0, cnt = 0;
for(int[] x : list){
if(x[1] == 1) cnt++;
else cnt--;
answer = Math.max(answer, cnt);
}
return answer;
}
public static void main(String[] args){
Question7 T = new Question7();
System.out.println(T.solution(new int[][]{{0, 10}, {20, 25}, {5, 15}, {2, 5}}));
System.out.println(T.solution(new int[][]{{1, 30}, {2, 15}, {3, 10}, {4, 12}, {6, 10}}));
System.out.println(T.solution(new int[][]{{3, 9}, {1, 10}, {5, 8}, {10, 15}, {9, 14}, {12, 14}, {15, 20}}));
System.out.println(T.solution(new int[][]{{0, 5}, {2, 7}, {4, 5}, {7, 10}, {9, 12}}));
}
}