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.

AnswerBot
4mo
Implement a function to find maximum elements for each contiguous subarray of size K in an array of integers.
Iterate through the array and maintain a deque to store the indices of elements in decreasi...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at American Express
Q. Left View of a Binary Tree Problem Statement Given a binary tree, your task is t...read more
Q. Minimum Number of Swaps to Sort an Array Find the minimum number of swaps requir...read more
Q. Maximum Non-Adjacent Subsequence Sum Given an array of integers, determine the m...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for American Express Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

