As reported: Salesforce MTS (SDE-2) loop (Bangalore, Mar–Apr 2025), round 1 (DSA): this question, then Minimum Window Substring.
This is LeetCode 238 — Product of Array Except Self.
Given an integer array nums, return an array answer where answer[i] is the product of all elements of nums except nums[i]. Run in O(n) time without using division.
Example 1
nums = [1,2,3,4]
Output: [24,12,8,6]
Example 2
nums = [-1,1,0,-3,3]
Output: [0,0,9,0,0]
Constraints: 2 ≤ nums.length ≤ 10^5; -30 ≤ nums[i] ≤ 30; every prefix and suffix product fits in a 32-bit integer.
Code runner format: one line: nums as a JSON array. Implement productExceptSelf(nums); the harness prints the array.