Reported September 2020
Wells Fargosliding window

Most Negative Number in Each Window

Reported by candidates from Wells Fargo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Wells Fargo OA. Under 2s to a working solution.
Founder's read

Strip the wording off this Wells Fargo OA, reported in September 2020, and it's a sliding window minimum with one twist: if the minimum isn't negative, you output 0. That's it. With nums up to 200000 long, the brute force rescan of every window will time out, so the OA wants a monotonic deque. If you've got the invite and 48 hours, learn this one pattern cold. And if you blank mid-assessment, StealthCoder runs invisibly on your desktop and hands you the deque solution while the proctor sees nothing.

The problem

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 = 3
return = [-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 = 2
return = [0,0]
Neither length-2 window contains a negative value.
Example 3
nums = [-2,-2,-1]
k = 2
return = [-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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: the answer for each window is min(window minimum, 0). If the smallest value is negative, return it. Otherwise return 0. Zero and positives both collapse to 0, so you never need to special-case them. Compute the window minimum with a monotonic deque of indices. Keep values increasing from front to back. Before pushing index i, pop from the back while nums[back] >= nums[i]. Pop from the front when its index is at or before i-k. Once i >= k-1, the front is the minimum, so append min(nums[front], 0). Common pitfalls: storing values instead of indices so you can't expire them, using a heap without lazy deletion, and forgetting that a window of all positives returns 0, not the smallest positive. It's O(n) time. If the deque logic slips under pressure, StealthCoder is the live-OA hedge that gives you a clean version.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Most Negative Number in Each Window cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Wells Fargo's OA.

Wells Fargo reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Most Negative Number in Each Window FAQ

What's the trick in the Wells Fargo most negative number in each window problem?+

It's a sliding window minimum. Compute the minimum of each length-k window with a monotonic deque, then cap it at 0 with min(value, 0). Any window with no negative has a minimum of 0 or higher, so it correctly outputs 0. No special casing needed.

How hard is this OA question really?+

Medium-hard if you haven't seen the monotonic deque, easy if you have. The twist is tiny. The real test is whether you avoid the O(n*k) rescan, since n can reach 200000 and k can be close to n.

Can I use a heap instead of a deque?+

Yes, but it's clumsier. You'd push (value, index) pairs and lazily pop the top while its index is outside the window. That's O(n log n), which fits the constraints. The deque is O(n) and simpler to reason about once you know it.

What edge cases should I test?+

Test k equal to 1, where each element maps to itself if negative or 0 otherwise. Test k equal to nums.length, which gives one output. Test all positives, all negatives, and repeated values like [-2,-2,-1]. Duplicates matter for your pop condition on the deque.

How do I prepare for this in 48 hours?+

Write the sliding window maximum deque once from memory, then flip the comparison for minimum. Add the min(x, 0) cap. Run the three examples by hand. Practice the index expiry check, since that's where most bugs hide. One focused hour covers it.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Wells Fargo.

OA at Wells Fargo?
Invisible during screen share
Get it