Product of All Others
Given an integer array nums, return an array out where out[i] is the product of every element of nums except nums[i].
Do it in O(n) time without using division.
Example 1
Input: nums = [2, 3, 4, 5] Output: [60, 40, 30, 24]
Example 2
Input: nums = [-1, 1, 0, -3, 3] Output: [0, 0, 9, 0, 0]
Constraints
- 2 <= nums.length <= 10^5
- -30 <= nums[i] <= 30
- All products fit in a 32-bit integer.
Hint 1
out[i] = (product of everything left of i) × (product of everything right of i).
Hint 2
Fill left products in one pass and multiply in right products in a second pass.
Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Game Developer, Automation Test Engineer
Run checks your code on 2 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.