![]() |
VOOZH | about |
Given an integer array arr[], find the maximum of minimums for every window size from 1 to n. For each window size k, consider all contiguous subarrays of length k and determine the minimum element in each subarray. Among these minimum values, take the maximum one.
Example:
Input: arr[] = [10, 20, 30]
Output: [30, 20, 10]
Explanation: The max of min for every possible window size.
Size 1: min of [10], [20], [30], max of min is 30.
Size 2: min of [10, 20],[20,30] max of min is 20.
Size 3: min of [10,20,30], max of min is 10.Input: arr[] = [10, 20, 30, 50, 10, 70, 30]
Output: [70, 30, 20, 10, 10, 10, 10]
Explanation:
Size 1: min are [10, 20, 30, 50, 10, 70, 30], max of min is 70.
Size 2: min are [10, 20, 30, 10, 10, 30], max of min is 30.
Size 3: min are [10, 20, 10, 10, 10], max of min is 20.
Size 4–7: min are [10, 10, 10, 10], max of min is 10.
Table of Content
Compute the minimum of every possible window, For each window size from 1 to n and find the maximum of those minimums.
70 30 20 10 10 10 10
Use a deque with the sliding window technique to find the minimum element of every subarray of size k efficiently. Repeat this for k = 1 to n, and for each k, take the maximum among these minimum values.
70 30 20 10 10 10 10
70 30 20 10 10 10 10