Maximum of Minimum Values in All Subarrays - Problem
You are given an integer array nums of size n. You need to solve n queries for each integer i in the range 0 ≤ i < n.
To solve the ith query:
- Find the minimum value in each possible subarray of size
i + 1of the arraynums - Find the maximum of those minimum values
Return a 0-indexed integer array ans of size n such that ans[i] is the answer to the ith query.
A subarray is a contiguous sequence of elements in an array.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [7,9,8,6,2]
›
Output:
[9,8,7,6,2]
💡 Note:
Size 1: min values are [7,9,8,6,2], max = 9. Size 2: min values are [7,8,6,2], max = 8. Size 3: min values are [7,6,2], max = 7. Size 4: min values are [6,2], max = 6. Size 5: min value is [2], max = 2.
Example 2 — All Same Values
$
Input:
nums = [5,5,5,5]
›
Output:
[5,5,5,5]
💡 Note:
All elements are the same, so minimum of any subarray is 5, and maximum of minimums is always 5.
Example 3 — Decreasing Order
$
Input:
nums = [10,6,3,1]
›
Output:
[10,6,3,1]
💡 Note:
Size 1: max min = 10. Size 2: subarrays [10,6],[6,3],[3,1] have mins [6,3,1], max = 6. Size 3: subarrays [10,6,3],[6,3,1] have mins [3,1], max = 3. Size 4: subarray [10,6,3,1] has min = 1.
Constraints
- 1 ≤ nums.length ≤ 105
- -109 ≤ nums[i] ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array [7,9,8,6,2] with 5 elements
2
Process
For each size, find minimums of all subarrays, then take maximum
3
Output
Array [9,8,7,6,2] representing max of mins for each size
Key Takeaway
🎯 Key Insight: Each element dominates as minimum within a specific range of subarray sizes
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code