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

The problem involves finding the maximum element in each sliding window of size 'K' in an array of integers.

  • Iterate through the array and maintain a deque to store the indices of elements in the curre...read more

Help your peers!
Select
Add answer anonymously...

Top Data Analyst Interview Questions Asked at American Express

Q. How would you sort an array without using built-in sorting functions?
Q. Tell the output a**2
Q. What is the difference between append() and concat?
Data Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits