As reported: Amazon SDE1 (FTC) loop (June 2025, Amazon Chime), round 1 with an SDE1 interviewer — after a Leadership Principle question and Remove All Adjacent Duplicates in String II: for this second problem only the optimised intuition was asked, without code. Interviewers in this loop asked for the intuition first, then clarifications, then an optimisation, then code, then time and space complexity.
Given an integer array nums and a window size k, return for every contiguous window of size k (from left to right) the first negative number in that window, or 0 if the window has no negative number.
Example 1
nums = [-8,2,3,-6,10], k = 2
Output: [-8,0,-6,-6]
Windows: [-8,2], [2,3], [3,-6], [-6,10].
Example 2
nums = [12,-1,-7,8,-15,30,16,28], k = 3
Output: [-1,-1,-7,-15,-15,0]
Constraints: 1 ≤ k ≤ nums.length ≤ 10⁵; -10⁵ ≤ nums[i] ≤ 10⁵.
Code runner format: one JSON value per line, in order: nums, k. Implement firstNegatives(nums, k); the harness prints the answers as a JSON array.