bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 209. Minimum Size Subarray Sum

209. Minimum Size Subarray Sum

Leetcode Solutions

Approach # Using pointers

  1. Initialize left pointer to 0 and sum to 0.
  2. Iterate over the nums array with an index i representing the end pointer of the current window.
    • Add nums[i] to sum.
    • While sum is greater than or equal to target:
      • Update ans to be the minimum of ans and the current subarray size i + 1 - left.
      • Subtract nums[left] from sum and increment left.
  3. If ans was updated during the process, return ans. Otherwise, return 0 if no such subarray was found.
UML Thumbnail

Approach # A better brute force

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...