
Asked in American Express
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!
Add answer anonymously...
Top Data Analyst Interview Questions Asked at American Express
Q. What is a p-value?
Q. Tell the output a**2
Q. Factors to account for ATM placements in city?
Interview Questions Asked to Data Analyst at Other Companies
Top Skill-Based Questions for American Express Data Analyst
Python Interview Questions and Answers
400 Questions
SQL Interview Questions and Answers
250 Questions
Machine Learning Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures 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

