Skip to content

Commit 6666846

Browse files
authored
Create Minimum_Platforms.java
1 parent 27e5f8d commit 6666846

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Arrays/Minimum_Platforms.java

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import java.util.*;
2+
import java.lang.*;
3+
import java.io.*;
4+
class GFG
5+
{
6+
public static void main (String[] args)
7+
{
8+
//code
9+
Scanner s = new Scanner(System.in);
10+
int t = s.nextInt();
11+
12+
while(t-- > 0){
13+
int n = s.nextInt();
14+
15+
int arr[] = new int[n];
16+
for(int i = 0 ; i < n ; i++){
17+
arr[i] = s.nextInt();
18+
}
19+
20+
int dept[] = new int[n];
21+
for(int i = 0 ; i < n ; i++){
22+
dept[i] = s.nextInt();
23+
}
24+
25+
Arrays.sort(arr);
26+
Arrays.sort(dept);
27+
28+
int i = 1;
29+
int j = 0;
30+
int plat = 1;
31+
int res = 1;
32+
33+
while(i < n && j < n){
34+
//if current arrival time is smaller than previous departure
35+
//time then, move to the next arrival time to see if that
36+
//too is smaller than previous departure time.
37+
if(arr[i] <= dept[j]){
38+
plat++;
39+
i++;
40+
}
41+
//If current arrival time is greater than previous departure
42+
//time then, move to next departure time to see if that
43+
//arrival time is greater than next departure too or not
44+
else{
45+
plat--;
46+
j++;
47+
}
48+
49+
res = Math.max(res, plat);
50+
}
51+
52+
System.out.println(res);
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)