First negative in window
Given an integer array and window size k, return for each window the first negative number in that window, or 0 if the window has no negative number. Slide the window left to right one step at a time. Use a deque so the whole pass is O(n). Return a list of length len(nums) - k + 1. 1 <= k <= len(nums) <= 10^5.
Implement
first_negative_window(nums: list[int], k: int) → list[int]Examples
in
[[12,-1,-7,8,-15,30,16,28],3]out[-1,-1,-7,-15,-15,0]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 20 min
solution.py
InputExpectedGot
[[12,-1,-7,8,-15,30,16,28],3][-1,-1,-7,-15,-15,0]not run yetsample