mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
59 lines
2.2 KiB
HTML
59 lines
2.2 KiB
HTML
<p>You are given an array of integers <code>nums</code> of length <code>n</code> and a <em>positive</em> integer <code>k</code>.</p>
|
|
|
|
<p>The <strong>power</strong> of an array is defined as:</p>
|
|
|
|
<ul>
|
|
<li>Its <strong>maximum</strong> element if <em>all</em> of its elements are <strong>consecutive</strong> and <strong>sorted</strong> in <strong>ascending</strong> order.</li>
|
|
<li>-1 otherwise.</li>
|
|
</ul>
|
|
|
|
<p>You need to find the <strong>power</strong> of all <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> of size <code>k</code>.</p>
|
|
|
|
<p>Return an integer array <code>results</code> of size <code>n - k + 1</code>, where <code>results[i]</code> is the <em>power</em> of <code>nums[i..(i + k - 1)]</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4,3,2,5], k = 3</span></p>
|
|
|
|
<p><strong>Output:</strong> [3,4,-1,-1,-1]</p>
|
|
|
|
<p><strong>Explanation:</strong></p>
|
|
|
|
<p>There are 5 subarrays of <code>nums</code> of size 3:</p>
|
|
|
|
<ul>
|
|
<li><code>[1, 2, 3]</code> with the maximum element 3.</li>
|
|
<li><code>[2, 3, 4]</code> with the maximum element 4.</li>
|
|
<li><code>[3, 4, 3]</code> whose elements are <strong>not</strong> consecutive.</li>
|
|
<li><code>[4, 3, 2]</code> whose elements are <strong>not</strong> sorted.</li>
|
|
<li><code>[3, 2, 5]</code> whose elements are <strong>not</strong> consecutive.</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">nums = [2,2,2,2,2], k = 4</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">[-1,-1]</span></p>
|
|
</div>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<div class="example-block">
|
|
<p><strong>Input:</strong> <span class="example-io">nums = [3,2,3,2,3,2], k = 2</span></p>
|
|
|
|
<p><strong>Output:</strong> <span class="example-io">[-1,3,-1,3,-1]</span></p>
|
|
</div>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= n == nums.length <= 10<sup>5</sup></code></li>
|
|
<li><code>1 <= nums[i] <= 10<sup>6</sup></code></li>
|
|
<li><code>1 <= k <= n</code></li>
|
|
</ul>
|