Hello,
Just wanted some feedback on runtime analysis. I’m still learning. My question is whether the solution I came up with below runs in O(N^4) or O(N^3). Or something else entirely. Thanks in advance.
const find_subarrays = function(arr, target) {
let result = [];
let intermediaryArray = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i] < target) {
result.push(arr[i]);
}
intermediaryArray = [];
intermediaryArray.push(arr[i]);
for (let j = i + 1; j < arr.length; j++) {
intermediaryArray.push(arr[j]);
const product = intermediaryArray.reduce((acc, curr) => acc * curr);
if (product < target) {
result.push(intermediaryArray.slice());
}
}
}
return result;
};