Class Solution
java.lang.Object
g2401_2500.s2420_find_all_good_indices.Solution
2420 - Find All Good Indices.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of size <code>n</code> and a positive integer <code>k</code>.</p>
<p>We call an index <code>i</code> in the range <code>k <= i < n - k</code> <strong>good</strong> if the following conditions are satisfied:</p>
<ul>
<li>The <code>k</code> elements that are just <strong>before</strong> the index <code>i</code> are in <strong>non-increasing</strong> order.</li>
<li>The <code>k</code> elements that are just <strong>after</strong> the index <code>i</code> are in <strong>non-decreasing</strong> order.</li>
</ul>
<p>Return <em>an array of all good indices sorted in <strong>increasing</strong> order</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [2,1,1,1,3,4,1], k = 2</p>
<p><strong>Output:</strong> [2,3]</p>
<p><strong>Explanation:</strong> There are two good indices in the array:</p>
<ul>
<li>
<p>Index 2. The subarray [2,1] is in non-increasing order, and the subarray [1,3] is in non-decreasing order.</p>
</li>
<li>
<p>Index 3. The subarray [1,1] is in non-increasing order, and the subarray [3,4] is in non-decreasing order.</p>
</li>
</ul>
<p>Note that the index 4 is not good because [4,1] is not non-decreasing.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [2,1,1,2], k = 2</p>
<p><strong>Output:</strong> []</p>
<p><strong>Explanation:</strong> There are no good indices in this array.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>3 <= n <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i] <= 10<sup>6</sup></code></li>
<li><code>1 <= k <= n / 2</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
goodIndices
-