Product Except Self With Zeros
Reported by candidates from Apple's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Apple OA is reaching for division without thinking about zeros. Apple reported this one in July 2026: return an array where each slot holds the product of everything except nums[i]. It looks like the classic prefix and suffix problem, but the reported version spells out three zero cases. Zero zeros, one zero, two or more. If you blank on the case split, StealthCoder runs invisibly during the live OA and gives you a working solution as a safety net. Know the cases cold and you won't need it.
The problem
You are given an integer array nums. Return an array result where result[i] is the product of all elements in nums except nums[i]. The source solution explicitly handled three zero cases: If there are no zeroes, each position receives the product of all numbers divided by the current value. If there is exactly one zero, only the zero position receives the product of all non-zero values. If there is more than one zero, every output value is 0. Function productExceptSelf(nums: int[]) → int[] Examples Example 1 nums = [1,2,0,4] return = [0,0,8,0] The source shared the rule but did not include this exact sample. FastPrep added this small example so the behavior can be checked directly. Constraints The source expects integer input. The source solution uses integer division in the no-zero case.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is counting zeros before you multiply anything. Walk the array once, multiply all non-zero values, and count the zeros. Then branch. No zeros: each output is total divided by nums[i], using integer division. Exactly one zero: the zero's position gets the product of the non-zero values, everything else is 0. Two or more zeros: the whole array is 0. That's O(n) time and O(1) extra space beyond the output. The common pitfall is multiplying zeros into the total, which turns every answer into 0 and breaks the single-zero case. Another is dividing by zero in the no-zero branch by mistake. Check your code against [1,2,0,4], which should return [0,0,8,0]. If you'd rather skip division, prefix and suffix products also work, and they handle zeros for free. StealthCoder is the hedge if the live OA rattles you and the case split slips your mind.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Product Except Self With Zeros cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as product of array except self. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Apple's OA.
Apple reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Product Except Self With Zeros FAQ
What's the trick in the Apple Product Except Self With Zeros question?+
Count zeros first and multiply only the non-zero values. Then branch on the zero count. Zero zeros means divide the total by each element. One zero means only that position gets the product. Two or more means all zeros. It's one pass to count and one to fill.
How hard is this problem really?+
Easy to medium. The algorithm is short, but the zero cases trip people up. If you've seen the prefix and suffix version, you're fine. The hard part is staying careful under a timer, not the idea itself.
Can I solve it without division?+
Yes. Build a prefix product array going left to right, then multiply by a running suffix product going right to left. Zeros are handled naturally, so you skip the case split. The reported version explicitly used division with three zero cases, so either approach should produce the same output.
What edge cases should I test before submitting?+
Test [1,2,0,4], which gives [0,0,8,0]. Test an array with two zeros, which should give all zeros. Test an array with no zeros. Also try a single-element array and negative numbers, since integer division and signs can behave oddly.
How do I prepare for this in 48 hours?+
Write the zero-count solution from memory twice, then write the prefix and suffix version once. Run both on a few arrays with 0, 1, and 2 zeros. Apple reported this in July 2026, so it's recent. Focus on clean branching, not volume of problems.