FastPrepMaximum of Fixed-Window Minima

Maximum of Fixed-Window Minima

Roblox logoRoblox● MediumFULLTIMEOA
Learn

Problem statement

For every contiguous subarray of exactly x values in nums, find its minimum value. Return the maximum among all of those window minima.

Windows may overlap. This asks for the maximum of minima, not the minimum of window maxima, and it does not ask for the maximum element directly unless x = 1.

Function

maxWindowMinimum(nums: int[], x: int) → int

Examples

Example 1

nums = [2,5,4,6,1]x = 3return = 4

The three windows have minima 2, 4 and 1. Their maximum is 4.

Example 2

nums = [-3,-1,-2]x = 2return = -2

The minima are -3 and -2; the maximum is -2.

Example 3

nums = [7,4,9]x = 1return = 9

A one-element window has its own value as its minimum.

Constraints

  • 1 <= nums.length <= 1000.
  • 1 <= x <= nums.length.
  • -10^9 <= nums[i] <= 10^9.

More Roblox problems

See Roblox hiring insights
public int maxWindowMinimum(int[] nums, int x) {
    // write your code here
}
nums[2,5,4,6,1]
x3
expected4
Checking account…