Sliding Window Maximum Problem Statement
You are given an array/list of integers with length 'N'. A sliding window of size 'K' moves from the start to the end of the array. For each of the 'N'-'K'+1 possible windows, return the maximum element.
Input:
First line: Single integer ‘T’ indicating number of test cases.
Each test case consists of:
- First line: Two space-separated integers ‘N’ and ‘K’ (number of elements and window size).
- Second line: ‘N’ space-separated integers (array elements).
Output:
For each test case, return the output array containing the maximum elements of each sliding window, on separate lines.
Example:
Input:
T = 1
N = 8, K = 3
Array = [1, 3, -1, -3, 5, 3, 6, 7]
Output:
[3, 3, 5, 5, 6, 7]
Explanation:
The sliding maximums for each window of size 'K' are [3, 3, 5, 5, 6, 7].
Constraints:
- 1 <= T <= 50
- 1 <= N <= 10^4
- 1 <= K <= N
- 0 <= ARR[i] <= 10^5
- Time Limit: 1 sec

AnswerBot
4mo
Sliding window maximum problem where we find maximum element in each window of size K.
Use a deque to store indices of elements in decreasing order within the window.
Pop elements from the deque that ar...read more
Help your peers!
Add answer anonymously...
Lifesight Software Developer interview questions & answers
A Software Developer was asked Q. Sliding Window Maximum Problem Statement You are given an array/list of integers...read more
A Software Developer was asked Q. Combination Sum Problem Statement Given an array of distinct positive integers A...read more
A Software Developer was asked Q. Longest Substring with K Distinct Characters You are provided with a string S of...read more
Popular interview questions of Software Developer
A Software Developer was asked Q1. Sliding Window Maximum Problem Statement You are given an array/list of integers...read more
A Software Developer was asked Q2. Combination Sum Problem Statement Given an array of distinct positive integers A...read more
A Software Developer was asked Q3. Longest Substring with K Distinct Characters You are provided with a string S of...read more
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

