-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay75.java
More file actions
62 lines (62 loc) · 1.32 KB
/
Copy pathDay75.java
File metadata and controls
62 lines (62 loc) · 1.32 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
input:
4
2
3 6
3
1 3 5
5
1 2 5 6 7
9
1 2 5 6 7 8 11 12 13
Output
1 1
3 3
2 3
2 4
*/
import java.util.*;
public class Day75{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int tc = in.nextInt();
String out[] = new String[tc];
for (int i=0;i<tc ;i++ ) {
int total = in.nextInt();
int person[] = new int[total];
for (int j=0;j<total ;j++ ) {
person[j] = in.nextInt();
}
String res = "";
int count=1;
for (int j=0;j<total-1 ;j++ ) {
if (person[j+1]-person[j]<=2) {
count++;
}else{
res+=Integer.toString(count)+" ";
count=1;
}
}
res+=Integer.toString(count)+" ";
if (res.length()==2) {
out[i]=Character.toString(res.charAt(0))+" "+Character.toString(res.charAt(0));
}else{
String ressplit[] = res.split(" ");
int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
for (int j=0;j<ressplit.length ; j++) {
if (Integer.parseInt(ressplit[j])<min) {
min = Integer.parseInt(ressplit[j]);
}
if (Integer.parseInt(ressplit[j])>max) {
max = Integer.parseInt(ressplit[j]);
}
}
out[i] = Integer.toString(min)+" "+Integer.toString(max);
}
}
System.out.println("Output");
for (int i=0;i<tc ;i++ ) {
System.out.println(out[i]);
}
}
}