Compute product of array except self
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Take-home Project
Quick Answer: This question evaluates understanding of array manipulation, modular arithmetic, and algorithmic optimization by requiring computation of per-element products excluding the current element without division under a large modulus.
Constraints
- 1 <= len(nums) <= 200000
- 0 <= nums[i] <= 10^9
Examples
Input: ([1, 2, 3, 4],)
Expected Output: [24, 12, 8, 6]
Explanation: Standard example.
Input: ([0, 2, 3],)
Expected Output: [6, 0, 0]
Explanation: Single zero.
Input: ([0, 2, 0],)
Expected Output: [0, 0, 0]
Explanation: Multiple zeros.
Input: ([5],)
Expected Output: [1]
Explanation: The empty product for one element is 1.
Hints
- Store products before each index in a prefix pass, then multiply by suffix products.