Product of Array Except Self
Updated
Problem statement
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]At index 0, omit the first element and multiply the others: 2 * 3 * 4 = 24.
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 Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Subarray Sum Equals KServiceNow · ONSITE INTERVIEWServiceNow interview questions
- Count Subarrays with Equal Even and Odd CountsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Range Booking TotalsGoogle · ONSITE INTERVIEWGoogle interview questions
- Product of Array Except SelfWalmart Labs · ONSITE INTERVIEW
- Subarrays Whose Sum Is a Power of TwoKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions
- Count Subarrays with Sum KMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
- Product Of Array Except SelfInfosys · ONSITE INTERVIEWInfosys interview questions
- Centered K-by-K Submatrix SumsCitadel · ONSITE INTERVIEWCitadel interview questions
- Farthest Affordable Shop per QueryAdobe · ONSITE INTERVIEWAdobe interview questions