-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathMinimum_Platforms.java
48 lines (40 loc) · 1.02 KB
/
Minimum_Platforms.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
import java.util.*;
class Minimum_number_of_platform {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int[] arr = new int[n];
int[] dep = new int[n];
for(int i = 0; i<n; i++){
arr[i] = sc.nextInt();
}
for(int i = 0; i<n; i++){
dep[i] = sc.nextInt();
}
System.out.println(platform(arr, dep, n));
}
}
public static int platform(int[] arr, int[] dep, int n){
Arrays.sort(arr);
Arrays.sort(dep);
int plat = 1;
int result = 1;
int i = 1;
int j = 0;
while( i < n && j < n ){
if( arr[i] <= dep[j] ){
plat++;
i++;
}else if( arr[i] > dep[j] ){
plat--;
j++;
}
if( result < plat ){
result = plat;
}
}
return result;
}
}