Class Solution
-
- All Implemented Interfaces:
public final class Solution3254 - Find the Power of K-Size Subarrays I\.
Medium
You are given an array of integers
numsof lengthnand a positive integerk.The power of an array is defined as:
Its maximum element if all of its elements are consecutive and sorted in ascending order.
\-1 otherwise.
You need to find the power of all subarrays of
numsof sizek.Return an integer array
resultsof sizen - k + 1, whereresults[i]is the power ofnums[i..(i + k - 1)].Example 1:
Input: nums = 1,2,3,4,3,2,5, k = 3
Output: 3,4,-1,-1,-1
Explanation:
There are 5 subarrays of
numsof size 3:[1, 2, 3]with the maximum element 3.[2, 3, 4]with the maximum element 4.[3, 4, 3]whose elements are not consecutive.[4, 3, 2]whose elements are not sorted.[3, 2, 5]whose elements are not consecutive.
Example 2:
Input: nums = 2,2,2,2,2, k = 4
Output: -1,-1
Example 3:
Input: nums = 3,2,3,2,3,2, k = 2
Output: -1,3,-1,3,-1
Constraints:
1 <= n == nums.length <= 500<code>1 <= numsi<= 10<sup>5</sup></code>
1 <= k <= n
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntArrayresultsArray(IntArray nums, Integer k)-
-
Method Detail
-
resultsArray
final IntArray resultsArray(IntArray nums, Integer k)
-
-
-
-