Product of Array Except Self
medium⏱ 15 mintypescriptchallengesproblem-solving-intermediate-
LEARN BY DOINGPut your intuition to work3 steps
Product of Array Except Self
Use the lesson’s examples and explanation to check your idea.
Personal reflection. Nothing is sent to an AI service.24 12 8 6
Sample case — your program reads stdin and prints to stdout.
Starter Given an integer array nums, return an array answer such that answer[i] is the product of all elements except nums[i].
Solve in O(n) without using division.
Algorithm: Two passes - left products then right products.
Example: [1,2,3,4] → [24,12,8,6] (24=234, 12=134, 8=124, 6=123)
Input format
Line 1: n. Line 2: n space-separated integers.
Output format
n space-separated integers (products except self).
Constraints
2 ≤ n ≤ 10⁵, -30 ≤ nums[i] ≤ 30