Sliding Maximum Problem Statement
Given an array of integers ARR
of length 'N' and a positive integer 'K', find the maximum elements for each contiguous subarray of size K.
Example:
Input:
ARR = [3, 4, -1, 1, 5]
K = 3
Output:
[4, 4, 5]
Explanation:
The maximum elements of the subarrays are: [4, 4, 5]. For each subarray: first is [3, 4, -1] with maximum 4, second is [4, -1, 1] with maximum 4, and third is [-1, 1, 5] with maximum 5.
Constraints:
1 <= T <= 10
1 <= N <= 105
-105 <= arr[i] <= 105
1 <= K <= N
Input:
The first line of input contains a single integer 'T', representing the number of test cases. Each test case consists of two lines. The first line contains two space-separated integers: 'N' (array length) and 'K' (subarray size). The second line contains 'N' space-separated integers, representing the elements of the array.
Output:
For each test case, output 'X' space-separated integers, where 'X' is the number of subarrays of size 'K'. Each integer represents the maximum element in its respective subarray.
Note:
You do not need to print anything; just implement the relevant function.
Be the first one to answer
Add answer anonymously...
Top CommVault Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
CommVault Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app