Code Room
CodingMediumcod-g587
Subject DequeLevel Mid–Senior~20 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.