FastPrepSliding Window Maximum
Problems/Sliding Window Maximum

Sliding Window Maximum

Groww logoGroww● HardFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported task identifies this standard algorithmic exercise. The executable interface, bounds, deterministic tie rules, and examples are the documented practice contract.

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]

Each output is the largest value in the corresponding length-three window.

Example 2

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

The only window contains the only value.

Example 3

nums = [9,8,7,6]k = 2return = [9,8,7]

In a decreasing array, each window maximum is its leftmost value.

Constraints

  • 1 <= nums.length <= 100000
  • -1000000000 <= nums[i] <= 1000000000
  • 1 <= k <= nums.length

More Groww problems

  • Maximum Sum Desirable SubarrayPHONE SCREEN · Seen Oct 2026
  • Best Time to Buy and Sell Stock IIONSITE INTERVIEW · Seen Sep 2026
  • Minimum Candies by RatingONSITE INTERVIEW · Seen Sep 2026
See Groww hiring insights
Saved
class Solution {
    public int[] maxSlidingWindow(int[] nums, int k) {
        // Write your code here.
    }

}
Checking account…