Meta / Amazon / Google / Microsoft| Product of Array Except Self | LeetCode-238: Medium | JavaScript Implementation

JavaScript Implementation:

var productExceptSelf = function(nums) {
let prefix = [1]
let subfix = []
subfix[nums.length-1]=1
for(let i = 1;i<nums.length;i++){
prefix[i] = prefix[i-1] * nums[i-1]
}
for(let i = nums.length-2;i>=0;i--){
subfix[i]=subfix[i+1] * nums[i+1]
}

let answer = []
for(let i= 0;i<nums.length;i++){
answer.push(subfix[i]*prefix[i])
}
return answer
};

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store