First Negative Integer in Every Window
Given an integer array nums and an integer k, move a window of exactly k consecutive elements from left to right by one position at a time. Return the first…
Given an integer array `nums` and an integer `k`, move a window of exactly `k` consecutive elements from left to right by one position at a time. Return the first negative integer in every window, in window order. If a window contains no negative integer, return `0` for that window.
- `1 <= nums.length <= 10^5` - `-10^4 <= nums[i] <= 10^4` - `1 <= k <= nums.length` - The interactive visualizer accepts at most 12 values; longer valid inputs are execution-only.
Example 1: input nums = [12,-1,-7,8,-15,30,16,28], k = 3; output [-1,-1,-7,-15,-15,0]. The final window [30,16,28] has no negative value, so its output is 0.
Example 2: input nums = [1,2,3,4], k = 2; output [0,0,0]. None of the three windows contains a negative value.
Category: Sliding Window. Topic: sliding-window. Difficulty: Medium. Patterns: sliding-window.