Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 238 Product of Array Except Self - Problem Statement

Prefix and suffix products

This is Product of Array Except Self from LeetCode. Given an array numsnums, return an array answeranswer where answer[i]answer[i] is the product of all elements except nums[i]nums[i]. The twist: you can't use division, and you must solve it in O(n)O(n) time.

Without division, you can't just compute the total product and divide. What do you do? Think: products to the left of each index and products to the right. Combining both gives the answer without division.