Problem · Array

Sliding Window Maximum

Learn this problem
HardAmazonONSITE INTERVIEW
See Amazon hiring insights

Problem statement

Given an integer array nums and a window size k, return the maximum value in every contiguous window of length k, from left to right.

Function

maxSlidingWindow(nums: int[], k: int) → int[]

Examples

Example 1

nums = [1,3,-1,-3,5,3,6,7]k = 3return = [3,3,5,5,6,7]

Example 2

nums = [1]k = 1return = [1]

More Amazon problems

drafts saved locally
public int[] maxSlidingWindow(int[] nums, int k) {
  // write your code here
}
nums[1,3,-1,-3,5,3,6,7]
k3
expected[3,3,5,5,6,7]
checking account