-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowSize.java
40 lines (33 loc) · 1.08 KB
/
WindowSize.java
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
package Stack;
public class WindowSize {
static int arr[] = { 10, 20, 30, 50, 10, 70, 30 };
static void printMaxOfMin(int n)
{
// Consider all windows of different
// sizes starting from size 1
for (int k = 1; k <= n; k++) {
// Initialize max of min for current
// window size k
int maxOfMin = Integer.MIN_VALUE;
// Traverse through all windows of
// current size k
for (int i = 0; i <= n - k; i++) {
// Find minimum of current window
int min = arr[i];
for (int j = 1; j < k; j++) {
if (arr[i + j] < min)
min = arr[i + j];
}
// Update maxOfMin if required
if (min > maxOfMin)
maxOfMin = min;
}
// Print max of min for current
// window size
System.out.print(maxOfMin + " ");
}
}
public static void main(String[] args) {
printMaxOfMin(arr.length);
}
}