Minimum Size Subarray Sum With Negatives
Updated
Problem statement
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) → intExamples
Example 1
nums = [2,3,1,2,4,3]k = 7return = 2The subarray [4,3] has sum 7, and no one-element subarray reaches 7.
Example 2
nums = [2,-1,2]k = 3return = 3Only the complete subarray has sum at least 3.
Example 3
nums = [1,-1,1]k = 4return = 0No non-empty subarray reaches a sum of 4.
Constraints
1 <= nums.length <= 10^5.1 <= k <= 10^9.numsmay contain positive, zero, and negative integers.
More Tekion interview questions
- Largest Rectangle in HistogramONSITE INTERVIEW · Seen Sep 2026
- Next Greater Element to the RightONSITE INTERVIEW · Seen Sep 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Sep 2026
- Maximum Sum of a Unique-Element SubarrayONSITE INTERVIEW · Seen Jul 2026
- Number of IslandsONSITE INTERVIEW · Seen Jul 2026
- Set Matrix ZeroesONSITE INTERVIEW · Seen Jul 2026
- Peak Resource Usage Across Weighted IntervalsPHONE SCREEN · Seen Sep 2026
- Dungeon GamePHONE SCREEN · Seen Sep 2026
- IPOPHONE SCREEN · Seen Sep 2026
- Coin Game From The EndsPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Maximum Subarray Sum with Length at Most KOracle · ONSITE INTERVIEWOracle interview questions
- Shortest Subarray with Sum at Least KApple · ONSITE INTERVIEWApple interview questions
- Shortest Subarray with Sum at Least KGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Shortest Subarray with Sum at Least KGoogle · PHONE SCREENGoogle interview questions
- Profit AnalysisVirtu Financial · OAVirtu Financial interview questions
- Sliding Window MaximumAmazon · ONSITE INTERVIEW
- Sliding Window MaximumPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Sliding Window MaximumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Round-Robin Iterator over IteratorsBridge · ONSITE INTERVIEWBridge interview questions
- Count Subarrays with Equal Even and Odd CountsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions