FastPrepProduct Of Array Except Self
Problems/Product Of Array Except Self

Product Of Array Except Self

Freshworks logoFreshworks● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asked Product of Array Except Self with prefix and suffix products. The judged core task matches the visible source at about 99%; the no-division rule, examples, and numeric bounds are specified for practice.

You are given an integer array nums of length n.

Return an array answer of the same length where answer[i] is the product of every value in nums except nums[i].

The product of any prefix or suffix of nums fits in a 32-bit integer. Do not use the division operator.

Function

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

Examples

Example 1

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

The products excluding each index are 2*3*4, 1*3*4, 1*2*4, and 1*2*3.

Example 2

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

A single zero makes every other product zero. The product excluding that zero is -1*1*-3*3 = 9.

Constraints

  • 2 <= nums.length <= 10^5.
  • -30 <= nums[i] <= 30.
  • The product of any prefix or suffix of nums fits in a 32-bit integer.
  • Every output value answer[i] also fits in a signed 32-bit integer.

More Freshworks problems

  • LFU CachePHONE SCREEN · Seen Sep 2026
  • Flatten a Nested ArrayONSITE INTERVIEW · Seen Aug 2026
  • Stock Span IPHONE SCREEN · Seen Aug 2026
All Freshworks interview questionsSee Freshworks hiring insights
Saved
class Solution {
    public int[] productExceptSelf(int[] nums) {
      // Write your code here.
    }
}
Checking account…