Back to course home
0% completed
Vote For New Content
Alternate JS solution still. Is my time/space complexity accurate?
Zachary Nelson
Oct 30, 2024
I have a slightly different approach which I believe is O(n^2) time complexity, I imagine the space complexity is the same O(n^3) but correct me if I'm wrong.
class Solution { findSubarrays(arr, target) { let result = []; let l = 0; let r = 0; let runningSum = 1; while (r <= arr.length) { runningSum *= arr[r]; if (runningSum < target) { result.push(arr.slice(l, r + 1)); r++ } else { l += 1 runningSum = 1; r = l } } return result; } }
0
1
Comments
Comments