Link: https://leetcode.com/problems/minimum-size-subarray-sum/
Solution:
Topics: sliding window, binary search
Intuition
Straight forward problem. Use a sliding window to shrink the window and take the min window that satisfies the constraint.
The problem statement asks for an nlogn
solution as well, kind of tricky to come up with but the idea is that the the possible answer has a lower bound and upper bound…specifically a subarray of length 1 as the lower bound and a subarray of len(nums)
as the upper bound. If there exists a subarray of length k that satisfies the sum, then there is guaranteed to exist a subarray of length k+1 that also satisfies the constraint.
Implementation
Implementation (binary search)
Visual
Review 1
Easy problem. The binary search solution is stupid…no idea why they would ask for that as a follow up or why I found it tricky earlier.