-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode16
More file actions
173 lines (148 loc) · 2.28 KB
/
code16
File metadata and controls
173 lines (148 loc) · 2.28 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
Skip to content
Navigation Menu
Yamini-525
/
Practice-Coding-
Type / to search
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Settings
Creating a new file in Practice-Coding-
BreadcrumbsPractice-Coding-
/
code15
in
main
Edit
Preview
Indent mode
Spaces
Indent size
2
Line wrap mode
No wrap
Editing code15 file contents
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
63
64
65
66
67
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
class Result {
/*
* Complete the 'pickingNumbers' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY a as parameter.
*/
public static int pickingNumbers(List<Integer> a) {
int max=0;
Collections.sort(a);
for (int i = 0; i < a.size() - 1; i++) {
int count = 1;
for (int j = i + 1; j < a.size(); j++) {
if (Math.abs(a.get(i) - a.get(j)) <= 1) {
count++;
}
if (count > max) {
max = count;
}
}
}
return max;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int n = Integer.parseInt(bufferedReader.readLine().trim());
String[] aTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
List<Integer> a = new ArrayList<>();
for (int i = 0; i < n; i++) {
int aItem = Integer.parseInt(aTemp[i]);
a.add(aItem);
}
int result = Result.pickingNumbers(a);
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}
Use Control + Shift + m to toggle the tab key moving focus. Alternatively, use esc then tab to move to the next interactive element on the page.
New File at / · Yamini-525/Practice-Coding-