Skip to content

Instantly share code, notes, and snippets.

@naveedn
Last active March 19, 2018 04:05
Show Gist options
  • Save naveedn/93b7eaa01da0dbc9d3a1e7e45894cf15 to your computer and use it in GitHub Desktop.
Save naveedn/93b7eaa01da0dbc9d3a1e7e45894cf15 to your computer and use it in GitHub Desktop.
Medium Article Snippet
const input = [1,3,5,7];
function product(inputArr) {
const output = [];
for (let i = 0; i < inputArr.length; i++) {
let product = 1;
for (let j = 0; j < inputArr.length; j++) {
if (i !== j) {
product *= inputArr[j];
}
}
output.push(product);
product = 1;
}
return output;
}
console.log(product(input));
@naveedn
Copy link
Author

naveedn commented Mar 19, 2018

Algorithmic Complexity:

Speed: O(n*2)
Space: O(n)

Next Approach: https://gist.github.com/naveedn/b16bd0a15ba089c58187eeacf4448efa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment