Compute product of all elements except self for arr=[1,2,3,4] without division. Prefix products: [1,1,2,6] (product of elements before i). Suffix products: [24,12,4,1] (product of elements after i).
Answer: prefix[i]×suffix[i]. For index 0: 1×24=24. For index 1: 1×12=12. For index 2: 2×4=8. For index 3: 6×1=6. Result: [24,12,8,6]. This handles zeros correctly: if one zero exists, only its position has nonzero result.