loading...

re: Daily Coding Problem #2 VIEW POST

FULL DISCUSSION
 

JavaScript O(n) but with division:

function Problem02(arr) {
  let mult = arr.slice(1).reduce((a, b) => a * b, 1);
  const res = [mult];

  for (let i = 1; i < arr.length; i++) {
    mult = mult * arr[i - 1] / arr[i];
    res.push(mult); // res[i] = mult;
  }

  console.log(res)
}
Code of Conduct Report abuse