← 返回 pinterest 的题目列表Check If All Numbers in a Window Are Monotonic
类型:online_judge
Problem Description
Given an integer array nums and an integer k, determine for each contiguous subarray of length k in the array whether it is monotonically decreasing or not. Return a boolean array where each element indicates whether the corresponding subarray satisfies the condition.
Input
An integer array nums
An integer k
Output
A boolean array indicating whether each subarray of length k is monotonically decreasing
Example
Example 1:
Input: nums = [4, 3, 2, 1], k = 3
Output: [true, true]
Explanation:
- The subarray [4, 3, 2] is monotonically decreasing.
- The subarray [3, 2, 1] is monotonically decreasing.
**Example 2:**
Input: nums = [1, 2, 3, 4], k = 2
Output: [false, false, false]
Explanation:
- The subarray [1, 2] is not monotonically decreasing.
- The subarray [2, 3] is not monotonically decreasing.
- The subarray [3, 4] is not monotonically decreasing.
## Constraints
- `1 <= nums.length <= 10^5`
- `1 <= k <= nums.length`
Example
Input
4 3
4 3 2 1