229. Maximum of Minimums for Every Window Size

Given an array arr[] of size n, for every window size i from 1 to n, find the maximum of the minimum of all contiguous subarrays of size i.

Return an array of size n where the i-th element contains the maximum of minimums for window size i + 1.

Example 1:

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

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

Explanation:  

  • Window size 1: max of [10, 20, 30, 50, 10, 70, 30] → 70  
  • Window size 2: max of [10,20], [20,30], ..., [70,30] → max of all mins → 30  
  • ... and so on.

Example 2:

Input: arr = [6, 3, 5, 1, 12]

Output: [12, 3, 3, 1, 1]

Now Your Turn!

Pick the correct output for the given input

Input: arr = [1, 2, 3, 4]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= n <= 105
  • 1 <= arr[i] <= 106

Fun Facts

0
class Solution {
public:
vector<int> maxOfMin(vector<int>& arr) {
// Your code goes here
}
};
 
Test Case

Input:

Arr