human
Solve in Python:
Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.

Example: 

Input: s = 7, nums = [2,3,1,2,4,3]
Output: 2
Explanation: the subarray [4,3] has the minimal length under the problem constraint.

Follow up:

If you have figured out the O(n) solution, try coding another solution of which the time complexity is O(n log n).
assistant
#Here is Python program to find the minimal length of a contiguous subarray of which the sum ≥ s.

class Solution:
     def minSubArrayLen(self, s, nums):
         """
         :type s: int
         :type nums: List[int]
         :rtype: int
         """
         if nums is None or len(nums) == 0:
             return 0
         running_sum = [nums[0]]
         for num in nums[1:]:
             running_sum.append(running_sum[-1] + num)
         def sub_sum(i,j):
             to_remove = 0 if i == 0 else running_sum[i-1]
             to_add = 0 if j == 0 else running_sum[j-1]
             return to_add - to_remove
         min_seen = float('inf')
         fast = 0
         slow = 0
         while fast < len(nums):
             while sub_sum(slow, fast) < s and fast < len(nums):
                 fast += 1
             while sub_sum(slow, fast) >= s and slow <= fast:
                 min_seen = min(min_seen, fast - slow)
                 slow += 1
         return 0 if min_seen == float('inf') else min_seen