Problem title
Difficulty
Avg time to solve

Power Set
Easy
15 mins
Maximum activities
Easy
15 mins
Find The Repeating And Missing Number
Easy
10 mins
Minimum Removals
Moderate
15 mins
Find Peak Element
Easy
15 mins
BST Iterator
Moderate
20 mins
Divide Two Integers
Easy
10 mins
Kth Element of Two Sorted Arrays
Hard
10 mins
Print Name and age
Easy
--
Check Permutation
Easy
-- 13

# Sliding Maximum

Difficulty: MEDIUM
Avg. time to solve
25 min
Success Rate
85%

Problem Statement

#### You are given an array 'ARR' of integers of length 'N' and a positive integer 'K'. You need to find the maximum elements for each and every contiguous subarray of size K of the array.

##### For example
``````'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].
``````
##### Input format:
``````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.
``````
##### Output Format :
``````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.
``````
##### Note:
``````You do not need to print anything; it has already been taken care of. Just implement the given function.
``````
##### Constraint :
``````1 <= T <= 10
1 <= N <= 10^5
-10^5 <= arr[i] <= 10^5
1 <= K <= N

Time Limit: 1 sec
``````
##### Sample Input 1 :
``````1
5 3
3 2 -6 1 0
``````
##### Sample Output 1:
``````3 2 1
``````
##### Explanation for Input 1:
``````The subarray of length 'K'      maximum element of the subarray.
3 2 -6                                    3
2 -6 1                                    2
-6 1 0                                    1

Thus, you need to return "3 2 1".
``````
##### Sample Input 2 :
``````1
9 3
1 2 3 1 4 5 2 3 6
``````
##### Sample Output 2:
``````3 3 4 5 5 5 6
``````   Console