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

Product of Array Except Self

Capgemini logoCapgemini● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported task identifies this standard algorithmic exercise. The executable interface, bounds, deterministic tie rules, and examples are the documented practice contract.

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 Capgemini problems

  • Most Recent Order for Each CustomerONSITE INTERVIEW · Seen Oct 2026
  • Contains DuplicatePHONE SCREEN · Seen Sep 2026
  • Detect a Linked-List CycleONSITE INTERVIEW · Seen Sep 2026
All Capgemini interview questionsSee Capgemini hiring insights
Saved
class Solution {
    public int[] productExceptSelf(int[] nums) {
      // write your code here
    }

}
Checking account…