Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Max of min for every window

Hard Acceptance 50.00% Points 40.00

Given an array of integers arr[], the task is to find the maximum of the minimum values for every possible window size in the array, where the window size ranges from 1 to arr.size().

More formally, for each window size k, determine the smallest element in all windows of size k, and then find the largest value among these minimums where 1<=k<=arr.size().

Examples
Example 1

Example 1

Input: arr[] = [10, 20, 30, 50, 10, 70, 30]

Output: [70, 30, 20, 10, 10, 10, 10]

Explanation: 1. First element in output indicates maximum of minimums of all windows of size 1. Minimums of windows of size 1 are [10], [20], [30], [50], [10], [70] and [30]. Maximum of these minimums is 70. 2. Second element in output indicates maximum of minimums of all windows of size 2. Minimums of windows of size 2 are [10], [20], [30], [10], [10], and [30]. Maximum of these minimums is 30. 3. Third element in output indicates maximum of minimums of all windows of size 3. Minimums of windows of size 3 are [10], [20], [10], [10] and [10]. Maximum of these minimums is 20. Similarly other elements of output are computed.

Example 2

Example 2

Input: arr[] = [10, 20, 30]

Output: [30, 20, 10]

Explanation: First element in output indicates maximum of minimums of all windows of size 1. Minimums of windows of size 1 are [10] , [20] , [30]. Maximum of these minimums are 30 and similarly other outputs can be computed

Hints
Hint 1
NA
Constraints
  • 1 <= arr.size() <= 10^5
  • 1 <= arr[i] <= 10^6
Companies
Amazon Microsoft Flipkart
Topics
Stack
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions