Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Minimum Size Subarray Sum

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Minimum Size Subarray Sum. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given an array of positive integers nums and a positive integer target, return the minimum length of a contiguous subarray whose sum is greater than or equal to target. If no such subarray exists, return 0.

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^4
  • 1 <= target <= 10^9

Function Signature

def min_subarray_len(target, nums):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output