Shortest Subarray with at least K as sum

In this problem, we find the length of the Shortest Subarray with at least K as sum. This can be solved in O(N) time complexity. This brings in the ideas of Monotonic Queue and Sliding Window.

Table of contents:

Problem StatementHow to approach?Brute Force approachHow to Optimize?Problem Statement

Return the length of the shortest, non-empty, contiguous subarray of nums with sum at least k.

If there is no non-empty subarray with sum at least k, return -1.

Example 1:

Input: nums = [1], k = ...
 •  0 comments  •  flag
Share on Twitter
Published on July 21, 2021 14:17
No comments have been added yet.