FastPrepMinimum of Fixed-Window Maxima
Problem · Array

Minimum of Fixed-Window Maxima

Learn this problem
MediumJuspay logoJuspayNEW GRADOA

Problem statement

You are given an integer array nums and an integer k. Consider every contiguous subarray of exactly k elements.

Compute the maximum value in each such window, then return the minimum among all of those window maxima.

Function

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

Examples

Example 1

nums = [1,3,2,5,1,4]k = 3return = 3

The four window maxima are 3, 5, 5, and 5. Their minimum is 3.

Example 2

nums = [-4,-2,-7,-3]k = 2return = -3

The window maxima are -2, -2, and -3. The minimum is -3.

Example 3

nums = [5,1,5]k = 1return = 1

With k = 1, every element is its own window maximum. The smallest of 5, 1, and 5 is 1.

Constraints

  • 1 <= nums.length.
  • 1 <= k <= nums.length.
  • Every value in nums is a signed 32-bit integer.

More Juspay problems

drafts saved locally
public int minimumWindowMaximum(int[] nums, int k) {
  // Write your code here.
}
nums[1,3,2,5,1,4]
k3
expected3
checking account