Most Negative Number in Each Window
Updated
Problem statement
Given an integer array nums and an integer window length k, return one value for every contiguous subarray of length k, in left-to-right window order.
For a window that contains at least one negative value, return its most negative value: the numerically smallest value in that window. If a window contains no negative value, return 0.
Function
mostNegativeInWindows(nums: int[], k: int) → int[]Examples
Example 1
nums = [12,-1,-7,8,-15,30,16,28]k = 3return = [-7,-7,-15,-15,-15,0]The first window [12,-1,-7] contributes -7. The last window [30,16,28] has no negative value, so it contributes 0.
Example 2
nums = [5,4,3]k = 2return = [0,0]Neither length-2 window contains a negative value.
Example 3
nums = [-2,-2,-1]k = 2return = [-2,-2]Repeated values are retained normally. The smallest negative value in each window is -2.
Constraints
1 <= nums.length <= 200000.1 <= k <= nums.length.-10^9 <= nums[i] <= 10^9.
More Wells Fargo Online Assessment questions
- Server Upgrade PlanningOA · Seen Nov 2026
- Student and Course EnrollmentOA · Seen Nov 2026
- Bond Interest Summary Above 3%OA · Seen Oct 2026
- Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
- Event Statistics AggregatorOA · Seen Sep 2026
- Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
- Longest Subsequence That Is a SubstringOA · Seen Jul 2026
- Overloaded Game Account InventoriesOA · Seen Jul 2026
- Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
- Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026
Similar questions at other companies
- Minimum of Fixed-Window MaximaJuspay · OA
- Maximum of Subarray MinimumsJP Morgan Chase · OAJP Morgan Chase interview questions
- Profit AnalysisVirtu Financial · OAVirtu Financial interview questions
- Maximum of Fixed-Window MinimaRoblox · OARoblox interview questions
- Incident MonitorStripe · OAStripe interview questions
- Longest Subarray Within an Absolute-Difference LimitGoogle · ONSITE INTERVIEWGoogle interview questions
- Longest Continuous Subarray Within an Absolute-Difference LimitUber · ONSITE INTERVIEWUber interview questions
- Disk Space Window AnalyzerAgoda · PHONE SCREENAgoda interview questions
- Sliding-Window Rate LimiterSnowflake · ONSITE INTERVIEWSnowflake interview questions
- Longest Continuous Subarray Within an Absolute-Difference LimitOracle · PHONE SCREENOracle interview questions