Menu
Coddy logo textTech

min_subarray_len

Lesson 10 of 15 in Coddy's Dynamic Programming 101 course.

The "min_subarray_len" challenge involves finding the minimum length of a contiguous subarray of a given array that has a sum greater than or equal to a target value. It requires a dynamic programming approach that involves keeping track of the running sum and updating the minimum subarray length as we iterate through the array.

challenge icon

Challenge

Hard

You are given an array of integers nums and a target integer target. Your function min_subarray_len needs to find a subarray of nums that sums up to target and has the minimum length. If there is no such subarray, it should return -1.

 

  • Example Input: nums = [2, 3, 1, 2, 4, 3], target = 7
  • Example Output: 2

Try it yourself

def min_subarray_len(nums, target):
    # Write code here

All lessons in Dynamic Programming 101