624. Maximum of Minimum for Every Window Size

MediumStackMonotonic StackArray

Given an array arr, for every window size from 1 to n compute the minimum of each window of that size, then take the maximum of those minimums. Return an array where position i (1-indexed) holds the answer for window size i. The input is JSON {arr}.

Input: JSON {arr}.

Output: Array — the answer for each window size 1..n.

Examples

Example 1
Input: {"arr":[10,20,30,50,10,70,30]}
Output: [70,30,20,10,10,10,10]
Explanation: Best minimum for each window size.
Example 2
Input: {"arr":[5]}
Output: [5]
Explanation: Only one window.
Example 3
Input: {"arr":[10,10,10]}
Output: [10,10,10]
Explanation: All equal.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →