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

Product of Array Except Self

Walmart Labs logoWalmart Labs● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names product except self without additional rules. This exercise uses the conventional no-division contract with explicit empty-product and numeric conventions; approximate source match: 95%.

Given nums, return an array whose element at index i is the product of every input element except nums[i]. Do not use division.

For this exercise, assume the product of an empty set is 1. Thus an empty input returns [], and a one-element input returns [1]. Zeros and negative values are allowed. Aim for linear time and constant auxiliary space excluding the returned array.

Function

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

Examples

Example 1

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

For each position, multiply the other three numbers. Leaving out the first gives two times three times four, which is twenty-four. Leaving out the second gives twelve, the third gives eight, and the fourth gives six.

Example 2

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

The zero is the only number whose own slot can be nonzero. Leaving it out gives minus one times one times minus three times three, which is nine. Every other slot still contains the zero, so it is zero.

Example 3

nums = []return = []

The array is empty, so the answer is an empty array.

Constraints

  • 0 <= nums.length <= 100.
  • -10 <= nums[i] <= 10.
  • The product of the absolute values of all nonzero elements is at most 2^31 - 1; all intermediate and output products fit a signed 32-bit integer.

More Walmart Labs Onsite Interview questions

  • Delayed Job SchedulerONSITE INTERVIEW · Seen Oct 2026
  • Find the Duplicate NumberONSITE 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
  • 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
  • Product of Array Except SelfSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
See Walmart Labs hiring insights
Saved
class Solution {
    public int[] productExceptSelf(int[] nums) {
        // Write your code here.
    }
}
Checking account…