-
Notifications
You must be signed in to change notification settings - Fork 0
/
Meeting rooms
48 lines (39 loc) · 1.24 KB
/
Meeting rooms
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
//Meeting rooms
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
while(T-- > 0) {
int n = Integer.parseInt(br.readLine().trim());
int[][] arr = new int[n][2];
for(int i = 0; i < n; i++) {
String temp[] = br.readLine().trim().split(" ");
arr[i][0] = Integer.parseInt(temp[0]);
String x = temp[1];
arr[i][1] = Integer.parseInt(x);
}
Solution obj = new Solution();
boolean ans = obj.canAttend(arr);
if(ans) {
System.out.println("true");
}
else {
System.out.println("false");
}
}
}
}
class Solution {
static boolean canAttend(int[][] arr) {
int n = arr.length;
Arrays.sort(arr, (a, b) -> Integer.compare(a[0], b[0]));
for(int i = 0; i < n - 1; i++) {
if (arr[i][1] > arr[i + 1][0]) {
return false;
}
}
return true;
}
}