Compute Product Except Current Element
ARRAY

Problem

Given an integer array nums, return a new array where each element at index i is the product of all elements in nums except the one at index i.

Can you do it in O(n) time and without division?

Examples

compute([5, 3, 4, 2]) // return [24, 40, 30, 60] /* Why? 3 * 4 * 2 = 24 5 * 4 * 2 = 40 5 * 3 * 2 = 30 5 * 3 * 4 = 60 */ compute([2, 0, 3, 4]) // return [0, 24, 0, 0]
Loading...
Loading...
Loading...