Product of Array Except Self
Updated
Problem statement
Given an integer array nums, return an array answer where answer[i] is the product of every element of nums except nums[i].
Build the result without using division and in linear time.
Function
productExceptSelf(nums: int[]) → int[]Examples
Example 1
nums = [1,2,3,4]return = [24,12,8,6]Each position contains the product of all values except the one at that position.
Example 2
nums = [-1,1,0,-3,3]return = [0,0,9,0,0]Only the index containing 0 receives the product of all nonzero values.
Constraints
2 <= nums.length <= 100000-30 <= nums[i] <= 30- Every prefix product and suffix product fits in a signed 32-bit integer.
- Do not use division.
- Your algorithm must run in
O(n)time.
More Squarepoint Capital interview questions
- Mutable Record Store with Error ResultsONSITE INTERVIEW · Seen Sep 2026
- Maximum SubarrayONSITE INTERVIEW · Seen Aug 2026
- Estimate Pi with a Finite SeriesONSITE INTERVIEW · Seen Oct 2025
- In-Memory Directory and File OperationsONSITE INTERVIEW · Seen Oct 2025
- Count C++ Constructor and Assignment CallsONSITE INTERVIEW · Seen Jun 2025
- Observe a Lazy GeneratorONSITE INTERVIEW · Seen Feb 2025
- Order Matching on ExecuteONSITE INTERVIEW · Seen Dec 2024
- Accumulate Numeric Value ObjectsONSITE INTERVIEW · Seen Sep 2024
- Differentiate a PolynomialONSITE INTERVIEW · Seen Aug 2023
- Lazy Filter over a GeneratorPHONE SCREEN · Seen Nov 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