Reported July 2025
Tekionprefix sum

Minimum Size Subarray Sum With Negatives

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

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

The trap in this Tekion OA, reported in July 2025, is the classic sliding window that quietly stops working the moment a negative number shows up. Most candidates have the positive-only version memorized, so they paste it in and fail hidden tests. This one is the prefix-sum plus monotonic deque problem, same family as shortest subarray with sum at least K. With n up to 10^5, brute force dies. If you blank on the deque logic during the live assessment, StealthCoder is the invisible safety net that reads the problem and hands you the working approach.

The problem

Given an integer array nums, which may contain negative values, and a positive integer k, return the minimum length of a non-empty contiguous subarray whose sum is at least k.
If no such subarray exists, return 0.

Function
minSubArrayLenWithNegatives(nums: int[], k: int) → int

Examples
Example 1
nums = [2,3,1,2,4,3]
k = 7
return = 2
The subarray [4,3] has sum 7, and no one-element subarray reaches 7.
Example 2
nums = [2,-1,2]
k = 3
return = 3
Only the complete subarray has sum at least 3.
Example 3
nums = [1,-1,1]
k = 4
return = 0
No non-empty subarray reaches a sum of 4.

Constraints
1 <= nums.length <= 10^5.
1 <= k <= 10^9.
nums may contain positive, zero, and negative integers.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Here's the trick. Build prefix sums P where P[i] is the sum of the first i elements. You want the smallest j - i such that P[j] - P[i] >= k. Negatives break the shrinking-window logic because extending the window can lower the sum, so two pointers miss valid answers. Instead keep a deque of indices with increasing prefix values. For each j, while the front satisfies P[j] - P[front] >= k, record the length and pop it. Then, while the back has P[back] >= P[j], pop it, since a later and smaller start is always better. Push j. Everything is O(n). Pitfalls: use 64-bit sums, start with P[0] = 0 and index 0 in the deque, and return 0 when nothing qualifies. Example 2, [2,-1,2] with k=3, is exactly where the naive window fails. StealthCoder is your hedge if the deque invariants slip live.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Minimum Size Subarray Sum With Negatives 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Tekion reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Size Subarray Sum With Negatives FAQ

What's the trick in the Tekion minimum size subarray with negatives question?+

Use prefix sums with a monotonic deque of indices. Pop from the front while the sum condition holds, and pop from the back while prefix values are not smaller than the current one. That gives O(n) and handles negatives, which a plain sliding window can't.

Why does the normal sliding window fail here?+

The standard window assumes adding elements only increases the sum and removing them only decreases it. With negatives, that breaks. A window that's too small may become valid after adding a negative then a large positive, so shrinking early throws away real answers.

How hard is this problem really?+

It's a hard-leaning medium. The prefix sum idea is simple, but the deque invariant is where people slip. If you've seen shortest subarray with sum at least K, it's quick. If not, expect to spend your time on the pop conditions.

What edge cases should I test before submitting?+

Test a single element at least k, all negatives, and no valid subarray returning 0. Also test example 2, [2,-1,2] with k=3, which needs the full array. Use 64-bit integers for prefix sums, since 10^5 values can overflow 32-bit.

How do I prepare for this in 48 hours?+

Write the prefix-sum deque solution from scratch twice, without looking. Then run the three given examples by hand, tracking the deque contents. Also practice explaining why you pop from the back. That's the part you'll forget under pressure.

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

OA at Tekion?
Invisible during screen share
Get it