|
| 1 | +# [1950. Maximum of Minimum Values in All Subarrays](https://leetcode.com/problems/maximum-of-minimum-values-in-all-subarrays) |
| 2 | + |
| 3 | +[中文文档](/solution/1900-1999/1950.Maximum%20of%20Minimum%20Values%20in%20All%20Subarrays/README.md) |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +<p>You are given an integer array <code>nums</code> of size <code>n</code>. You are asked to solve <code>n</code> queries for each integer <code>i</code> in the range <code>0 <= i < n</code>.</p> |
| 8 | + |
| 9 | +<p>To solve the <code>i<sup>th</sup></code> query:</p> |
| 10 | + |
| 11 | +<ol> |
| 12 | + <li>Find the <strong>minimum value</strong> in each possible subarray of size <code>i + 1</code> of the array <code>nums</code>.</li> |
| 13 | + <li>Find the <strong>maximum</strong> of those minimum values. This maximum is the <strong>answer</strong> to the query.</li> |
| 14 | +</ol> |
| 15 | + |
| 16 | +<p>Return <em>a <strong>0-indexed</strong> integer array</em> <code>ans</code> <em>of size </em><code>n</code> <em>such that </em><code>ans[i]</code> <em>is the answer to the </em><code>i<sup>th</sup></code> <em>query</em>.</p> |
| 17 | + |
| 18 | +<p>A <strong>subarray</strong> is a contiguous sequence of elements in an array.</p> |
| 19 | + |
| 20 | +<p> </p> |
| 21 | +<p><strong>Example 1:</strong></p> |
| 22 | + |
| 23 | +<pre> |
| 24 | +<strong>Input:</strong> nums = [0,1,2,4] |
| 25 | +<strong>Output:</strong> [4,2,1,0] |
| 26 | +<strong>Explanation:</strong> |
| 27 | +i=0: |
| 28 | +- The subarrays of size 1 are [0], [1], [2], [4]. The minimum values are 0, 1, 2, 4. |
| 29 | +- The maximum of the minimum values is 4. |
| 30 | +i=1: |
| 31 | +- The subarrays of size 2 are [0,1], [1,2], [2,4]. The minimum values are 0, 1, 2. |
| 32 | +- The maximum of the minimum values is 2. |
| 33 | +i=2: |
| 34 | +- The subarrays of size 3 are [0,1,2], [1,2,4]. The minimum values are 0, 1. |
| 35 | +- The maximum of the minimum values is 1. |
| 36 | +i=3: |
| 37 | +- There is one subarray of size 4, which is [0,1,2,4]. The minimum value is 0. |
| 38 | +- There is only one value, so the maximum is 0. |
| 39 | +</pre> |
| 40 | + |
| 41 | +<p><strong>Example 2:</strong></p> |
| 42 | + |
| 43 | +<pre> |
| 44 | +<strong>Input:</strong> nums = [10,20,50,10] |
| 45 | +<strong>Output:</strong> [50,20,10,10] |
| 46 | +<strong>Explanation:</strong> |
| 47 | +i=0: |
| 48 | +- The subarrays of size 1 are [10], [20], [50], [10]. The minimum values are 10, 20, 50, 10. |
| 49 | +- The maximum of the minimum values is 50. |
| 50 | +i=1: |
| 51 | +- The subarrays of size 2 are [10,20], [20,50], [50,10]. The minimum values are 10, 20, 10. |
| 52 | +- The maximum of the minimum values is 20. |
| 53 | +i=2: |
| 54 | +- The subarrays of size 3 are [10,20,50], [20,50,10]. The minimum values are 10, 10. |
| 55 | +- The maximum of the minimum values is 10. |
| 56 | +i=3: |
| 57 | +- There is one subarray of size 4, which is [10,20,50,10]. The minimum value is 10. |
| 58 | +- There is only one value, so the maximum is 10. |
| 59 | +</pre> |
| 60 | + |
| 61 | +<p> </p> |
| 62 | +<p><strong>Constraints:</strong></p> |
| 63 | + |
| 64 | +<ul> |
| 65 | + <li><code>n == nums.length</code></li> |
| 66 | + <li><code>1 <= n <= 10<sup>5</sup></code></li> |
| 67 | + <li><code>0 <= nums[i] <= 10<sup>9</sup></code></li> |
| 68 | +</ul> |
| 69 | + |
| 70 | +## Solutions |
| 71 | + |
| 72 | +<!-- tabs:start --> |
| 73 | + |
| 74 | +### **Python3** |
| 75 | + |
| 76 | +```python |
| 77 | + |
| 78 | +``` |
| 79 | + |
| 80 | +### **Java** |
| 81 | + |
| 82 | +```java |
| 83 | + |
| 84 | +``` |
| 85 | + |
| 86 | +### **...** |
| 87 | + |
| 88 | +``` |
| 89 | +
|
| 90 | +``` |
| 91 | + |
| 92 | +<!-- tabs:end --> |
0 commit comments