Shortest Subarray with Sum at Least K
Updated
Problem statement
Given a signed integer array nums and an integer k, return the length of the shortest nonempty contiguous subarray whose sum is at least k.
Return -1 if no such subarray exists.
Function
shortestSubarrayAtLeastK(nums: int[], k: long) → intExamples
Example 1
nums = [2,-1,2]k = 3return = 3Only the entire array reaches sum 3.
Example 2
nums = [1,2]k = 4return = -1No subarray reaches 4.
Constraints
1 <= nums.length <= 200000-10^9 <= nums[i] <= 10^91 <= k <= 10^18
More Goldman Sachs Phone Screen questions
- House Robber IIIPHONE SCREEN · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · Seen Nov 2026
- Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Check a Complete Binary TreePHONE SCREEN · Seen Oct 2026
- Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count Staircase WaysPHONE SCREEN · Seen Oct 2026
- Is a Power of TenPHONE SCREEN · Seen Oct 2026
- Minimum Traveling Salesperson TourPHONE SCREEN · Seen Oct 2026
- Square Root with Newton IterationPHONE SCREEN · Seen Oct 2026
- First Non-Repeating CharacterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Shortest Subarray with Sum at Least KGoogle · PHONE SCREEN
- Shortest Subarray with Sum at Least KOracle · ONSITE INTERVIEW
- Minimum Size Subarray Sum With NegativesTekion · ONSITE INTERVIEW
- Shortest Subarray with Sum at Least KApple · ONSITE INTERVIEW
- Profit AnalysisVirtu Financial · OA
- Count Non-Overlapping Pairs of Rectangles That Sum to KWisdomAI · PHONE SCREEN
- Sliding Window MaximumGroww · PHONE SCREEN
- Largest Value in Every Sliding WindowAdobe · PHONE SCREEN
- Sliding Window MaximumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
- Fixed Worker Pool with a Shared QueueSquarepoint Capital · PHONE SCREEN