Product of Array Except Self
medium⏱ 15 mintypescriptchallengesproblem-solving-intermediate-
Caso de ejemplo — tu programa lee de stdin e imprime en stdout.
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)
Formato de entrada
Line 1: n. Line 2: n space-separated integers.
Formato de salida
n space-separated integers (products except self).
Restricciones
2 ≤ n ≤ 10⁵, -30 ≤ nums[i] ≤ 30