Skip to main content
All Questions

Product of Array Except Self

Medium

Given an array nums of n integers where n > 1, return an array output such that each element at index i of output is equal to the product of all the numbers in the original array except nums[i].

Examples

nums = [1, 2, 3, 4] output: [24, 12, 8, 6] nums = [0, 0] output: [0, 0] nums = [4, 5, 1, 8, 2] output: [80, 64, 320, 40, 160] nums = [-2, 1, -3, 4, -1] output: [12, -24, 8, -6, 24]

Related courses

Course

Machine Learning Engineer Interview Prep

Land your dream machine learning role at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Explore ML system design, core concepts, coding, behavioral interviews, and more.

Course

Data Engineering Interview Prep

Land your dream data engineering role at Meta, Google, Amazon, Microsoft, Walmart, DoorDash, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Practice data modeling, pipeline design, SQL, coding, behavioral interviews, and more.