Algorithms Playbook
← All problems
MediumPrefix sums →Similar to: Product of Array Except Self

Everything but me

Problem

Given an array nums, return an array out where out[i] is the product of every element of nums except nums[i]. Do it in O(n) time and without using division.

Examples

Input: [2, 3, 4, 5]

Output: [60, 40, 30, 24]

out[0] = 3·4·5 = 60.

Input: [1, 0, 3]

Output: [0, 3, 0]

Hints

    Try it first. Every hint reveals a bit more.

    Solution