Given an array of positive integers and a number S, find the longest contiguous subarray having the sum at most S.
Return the start and end indices denoting this subarray.
Example
Input: nums = [3, 2, 5, 2, 2, 1, 1, 3, 1 , 2], S = 11
Output: [3, 8]
Explanation:the subarray nums[3...8] of sum 10
Note:
Your algorithm should run in O(n) time and use O(1) extra space.
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Solution #2 · O(n)
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check