FastPrepProduct of Array Except Self
Problems/Product of Array Except Self

Product of Array Except Self

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source links the canonical Product of Array Except Self task but does not reproduce its interface, examples, or constraints. The judged core task follows that canonical no-division linear-time contract and matches the visible source at about 99%.

Given an integer array nums, return an array answer where answer[i] equals the product of every element of nums except nums[i].

Solve the problem without division in O(n) time. The output array does not count as extra space.

Function

productExceptSelf(nums: int[]) → int[]

Examples

Example 1

nums = [1,2,3,4]return = [24,12,8,6]

For index 0, the product is 2 * 3 * 4 = 24; apply the same rule at every index.

Example 2

nums = [-1,1,0,-3,3]return = [0,0,9,0,0]

Only the position containing zero has a nonzero result, equal to (-1) * 1 * (-3) * 3 = 9.

Example 3

nums = [2,3]return = [3,2]

With two values, each output is the other value.

Constraints

  • 2 <= nums.length <= 10^5.
  • -30 <= nums[i] <= 30.
  • Every prefix product and suffix product fits in a signed 32-bit integer.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int[] productExceptSelf(int[] nums) {
      // write your code here
    }
}
Checking account…