Product of Array Except Self
Difficulty: Medium
Problem Statement:
You are given an integer array nums. Create and return a new array answer such that answer[i] is equal to the product of all the elements in nums except nums[i].
Requirements:
●The solution must run in O(n) time.
●You are not allowed to use division.
●The product of any prefix or suffix of the array is guaranteed to fit within a 32-bit integer.
Examples:
Input: nums = [1, 2, 3, 4]
Output: [24, 12, 8, 6]
Input: nums = [-1, 1, 0, -3, 3]
Output: [0, 0, 9, 0, 0]
Constraints:
2 ≤ nums.length ≤ 10⁵
-30 ≤ nums[i] ≤ 30
Can you solve it in O(n) time without using division?
Difficulty: Medium
Problem Statement:
You are given an integer array nums. Create and return a new array answer such that answer[i] is equal to the product of all the elements in nums except nums[i].
Requirements:
●The solution must run in O(n) time.
●You are not allowed to use division.
●The product of any prefix or suffix of the array is guaranteed to fit within a 32-bit integer.
Examples:
Input: nums = [1, 2, 3, 4]
Output: [24, 12, 8, 6]
Input: nums = [-1, 1, 0, -3, 3]
Output: [0, 0, 9, 0, 0]
Constraints:
2 ≤ nums.length ≤ 10⁵
-30 ≤ nums[i] ≤ 30
Can you solve it in O(n) time without using division?