mediumArraysPattern: Sliding Window
Minimum Sum Subarray Solution
Problem Statement
You are given an array of integers `nums` and a target sum `target`. Find the minimum window subarray that sums up to the `target`. If no such window exists, return an empty array.
Examples
Example 1:
Input:{"nums":[14203105],"target":33}
Output:[20310]
Explanation: The minimum window subarray that sums up to 33 is [20,3,10]
Example 2:
Input:{"nums":[12345],"target":15}
Output:[45123]
Explanation: The minimum window subarray that sums up to 15 is not [4,5], it's [4,5,1,2,3] or [1,2,3,4,5], the statement does not specify if the window has to be continuous, or the smallest window that can sum to the target
Constraints
- Input array is sorted in non-decreasing order. Target sum may be any positive integer.
Time: O(n) Space: O(1)
Use a two-pointer technique with a time complexity of O(n) to find the minimum window subarray
Run, Test & Submit Code
Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.
Solve on Interactive WorkspaceTested Solutions
No solution code is currently loaded.
Complete this code in the workspace editor.
