-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay 144.java
More file actions
35 lines (28 loc) · 782 Bytes
/
Day 144.java
File metadata and controls
35 lines (28 loc) · 782 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
import java.util.*;
class Solution {
public static int overlapInt(int[][] arr) {
int n = arr.length;
int[] start = new int[n];
int[] end = new int[n];
for (int i = 0; i < n; i++) {
start[i] = arr[i][0];
end[i] = arr[i][1];
}
Arrays.sort(start);
Arrays.sort(end);
int i = 0, j = 0;
int count = 0;
int maxOverlap = 0;
while (i < n && j < n) {
if (start[i] <= end[j]) {
count++;
maxOverlap = Math.max(maxOverlap, count);
i++;
} else {
count--;
j++;
}
}
return maxOverlap;
}
}