-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathP33.java
More file actions
32 lines (24 loc) · 713 Bytes
/
P33.java
File metadata and controls
32 lines (24 loc) · 713 Bytes
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
package stack_and_queue;
// .. First negative integer in every window of size "K"
public class P33 {
public long[] printFirstNegativeInteger(long[] a, int n, int k) {
long[] list = new long[n - k + 1];
for (int i = 0; i < n - k + 1; i++) {
int c = 0, count = 0;
while (c < k) {
if ((int) a[c + i] < 0) {
list[i] = a[c + i];
count = count + 1;
break;
}
c = c + 1;
}
if (count == 0)
list[i] = (long) 0;
count = 0;
}
return list;
}
public static void main(String[] args) {
}
}