Product except self
Return the product of every other number for each index, without division, in linear time. Empty input returns []; a single item returns [1].
items = [2, 3, 4]
prefix = 1
for value in items:
print(prefix)
prefix *= valueReason about the state
Store prefix products in the output, then multiply by a running suffix product. This handles zeros without special division cases. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return the product of every other number for each index, without division, in linear time. Empty input returns []; a single item returns [1].
The explanation opens here once every check passes.