Product Array
Given an array of integers, write a function buildProductArray that returns an array where each item is the product of all the items in the input array except for the item at that index.
Constraints:
- Solve this without using division
- You can create a
resultsarray, and it won't count against your space complexity - Memory may be a concern though, so try to limit your use of additional data structures
Breakdown
Validate My Answer
You may immediately recognize a brute force O(n2) answer. You can get this down to O(n).
You may want to add additional arrays to get the O(n) time complexity. However, you can solve this without any additional data structures other than your
resultsarray.To get it to O(n) without additional arrays, you may have to perform sequential O(n) time complexity operations.
Does your solution handle 0 or negative numbers?
Product Array
Given an array of integers, write a function buildProductArray that returns an array where each item is the product of all the items in the input array except for the item at that index.
Constraints:
- Solve this without using division
- You can create a
resultsarray, and it won't count against your space complexity - Memory may be a concern though, so try to limit your use of additional data structures