New update is available. Click here to update.

Posted: 13 Sep, 2020

Difficulty: Moderate

```
'ARR' = [3, 4, -1, 1, 5] and 'K' = 3
Output = [4, 4, 5]
Since the maximum element of the first subarray of length three ([3, 4, -1]) is 4, the maximum element of the second subarray of length three ([4, -1, 1]) is also 4 and the maximum element of the last subarray of length three ([-1, 1, 5]) is 5, so you need to return [4, 4, 5].
```

```
The first line of input contains a single integer 'T', representing the number of test cases or queries to be run. Then the 'T' test cases follow.
The first line of each test case contains two positive integers 'N' and 'K' which represent the length of the array and length of the subarray respectively.
The Second line of each test case contains 'N' space-separated integers representing the elements of the array.
```

```
For each test case, print 'X' space-separated integer denoting maximum elements for each and every contiguous subarray of size 'K' of the array. Where 'X' is the number of subarray of size 'K' in array 'arr'.
Output for each test case will be printed in a separate line.
```

```
You do not need to print anything; it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 10
1 <= N <= 10^5
-10^5 <= arr[i] <= 10^5
1 <= K <= N
Time Limit: 1 sec
```

SIMILAR PROBLEMS

Missing Number

Posted: 30 Oct, 2022

Difficulty: Easy

Longest Subarray With Zero Sum

Posted: 3 Nov, 2022

Difficulty: Moderate

Merge Two Sorted Arrays Without Extra Space

Posted: 19 Nov, 2022

Difficulty: Moderate

Ninja And The Strictly Increasing Array

Posted: 27 Nov, 2022

Difficulty: Moderate

Negative To The End

Posted: 16 Dec, 2022

Difficulty: Easy

Popular Interview Problems: