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

Shortest Subarray with Sum at Least K

Google logoGoogle● HardNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The Google ML new-grad report links this well-known exercise as a similar interview question. The linked statement gives the rules for negative values, the examples, and the limits. Our version is about 100% the same as the linked question.

Given an 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.

Values may be negative. A subarray is a contiguous part of the array.

Function

shortestSubarray(nums: int[], k: int) → int

Examples

Example 1

nums = [1]k = 1return = 1

The single-element subarray has sum 1.

Example 2

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

Even the sum of the entire array is below 4.

Example 3

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

Only the entire array reaches a sum of 3.

Constraints

  • 1 <= nums.length <= 100000.
  • -100000 <= nums[i] <= 100000.
  • 1 <= k <= 10^9.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Shortest Subarray with Sum at Least KGoldman Sachs · 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

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
See Google hiring insights
Saved
class Solution {
    public int shortestSubarray(int[] nums, int k) {
        // Write your code here
    }
}
Checking account…