-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem_1.c
63 lines (51 loc) · 1.33 KB
/
Problem_1.c
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
/*
Problem 1:
Given an array of numbers and a window size of k, print the maximum of numbers inside the window
for each step as the window moves from the biggining of array.
Input format:
input contains the array size , elements and the window size
Output format:
print the maximum of numbers
Sample input:
8
1 3 5 2 1 8 6 9
3
Sample output:
5 5 5 8 8 9
*/
#include <stdio.h>
#include <limits.h>
void main()
{
system("cls");
int size, array[100],windowSize,maxValue = INT_MIN;
printf("\nEnter the size of the array : ");
scanf("%d",&size);
for(int index = 0; index < size; index++ )
{
printf("\nEnter Element[%d] : ",(index + 1) );
scanf("%d",&array[index]);
}
printf("\nEnter Sliding window size : ");
scanf("%d",&windowSize);
if( windowSize > size )
{
windowSize = size;
}
for(int index = 0; index < size; index++ )
{
if(index + windowSize > size )
{
break;
}
for(int slidingIndex = index; slidingIndex < index + windowSize; slidingIndex++)
{
if(maxValue < array[slidingIndex])
{
maxValue = array[slidingIndex];
}
}
printf("%d\t",maxValue);
maxValue = INT_MIN;
}
}