FastPrepShortest Subarray with Sum at Least K
Problems/Shortest Subarray with Sum at Least K

Shortest Subarray with Sum at Least K

Goldman Sachs logoGoldman Sachs● HardFULLTIMEPHONE SCREEN

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Goldman Sachs CoderPad report links the exact Shortest Subarray with Sum at Least K exercise and says the test cases matched. This practice version is an approximately 99% match.

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) → int

Examples

Example 1

nums = [2,-1,2]k = 3return = 3

Only the entire array reaches sum 3.

Example 2

nums = [1,2]k = 4return = -1

No subarray reaches 4.

Constraints

  • 1 <= nums.length <= 200000
  • -10^9 <= nums[i] <= 10^9
  • 1 <= 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
See Goldman Sachs hiring insights
Saved
class Solution {
    public int shortestSubarrayAtLeastK(int[] nums, long k) {
      // write your code here
    }
}
Checking account…