|
| 1 | +<h2><a href="https://leetcode.com/problems/find-the-power-of-k-size-subarrays-ii">Find the Power of K-Size Subarrays II</a></h2> <img src='https://img.shields.io/badge/Difficulty-Medium-orange' alt='Difficulty: Medium' /><hr><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> |
| 2 | + |
| 3 | +<p>The <strong>power</strong> of an array is defined as:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <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> |
| 7 | + <li>-1 otherwise.</li> |
| 8 | +</ul> |
| 9 | + |
| 10 | +<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> |
| 11 | + |
| 12 | +<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> |
| 13 | + |
| 14 | +<p> </p> |
| 15 | +<p><strong class="example">Example 1:</strong></p> |
| 16 | + |
| 17 | +<div class="example-block"> |
| 18 | +<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4,3,2,5], k = 3</span></p> |
| 19 | + |
| 20 | +<p><strong>Output:</strong> [3,4,-1,-1,-1]</p> |
| 21 | + |
| 22 | +<p><strong>Explanation:</strong></p> |
| 23 | + |
| 24 | +<p>There are 5 subarrays of <code>nums</code> of size 3:</p> |
| 25 | + |
| 26 | +<ul> |
| 27 | + <li><code>[1, 2, 3]</code> with the maximum element 3.</li> |
| 28 | + <li><code>[2, 3, 4]</code> with the maximum element 4.</li> |
| 29 | + <li><code>[3, 4, 3]</code> whose elements are <strong>not</strong> consecutive.</li> |
| 30 | + <li><code>[4, 3, 2]</code> whose elements are <strong>not</strong> sorted.</li> |
| 31 | + <li><code>[3, 2, 5]</code> whose elements are <strong>not</strong> consecutive.</li> |
| 32 | +</ul> |
| 33 | +</div> |
| 34 | + |
| 35 | +<p><strong class="example">Example 2:</strong></p> |
| 36 | + |
| 37 | +<div class="example-block"> |
| 38 | +<p><strong>Input:</strong> <span class="example-io">nums = [2,2,2,2,2], k = 4</span></p> |
| 39 | + |
| 40 | +<p><strong>Output:</strong> <span class="example-io">[-1,-1]</span></p> |
| 41 | +</div> |
| 42 | + |
| 43 | +<p><strong class="example">Example 3:</strong></p> |
| 44 | + |
| 45 | +<div class="example-block"> |
| 46 | +<p><strong>Input:</strong> <span class="example-io">nums = [3,2,3,2,3,2], k = 2</span></p> |
| 47 | + |
| 48 | +<p><strong>Output:</strong> <span class="example-io">[-1,3,-1,3,-1]</span></p> |
| 49 | +</div> |
| 50 | + |
| 51 | +<p> </p> |
| 52 | +<p><strong>Constraints:</strong></p> |
| 53 | + |
| 54 | +<ul> |
| 55 | + <li><code>1 <= n == nums.length <= 10<sup>5</sup></code></li> |
| 56 | + <li><code>1 <= nums[i] <= 10<sup>6</sup></code></li> |
| 57 | + <li><code>1 <= k <= n</code></li> |
| 58 | +</ul> |
0 commit comments