File tree 1 file changed +55
-0
lines changed
1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments