FastPrepProduct Except Self With Zeros
Problems/Product Except Self With Zeros

Product Except Self With Zeros

Apple logoApple● MediumONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem is backed by an Apple interview-question post. The source code directly defines product except self and the three zero-count cases, but it did not include examples or constraints. The core task match is about 95%.

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].

Handle 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]

Only the index holding the zero gets a nonzero product; every other product includes the zero.

Constraints

  • The input contains integers.
  • In the no-zero case, integer division gives exact results.

More Apple problems

  • Evaluate DivisionPHONE SCREEN · Seen Nov 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
  • Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public int[] productExceptSelf(int[] nums) {
      // write your code here
    }
}
Checking account…