Advertisement
j-bennet

Array of Array Products

Jul 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. Array of Array Products
  2. Given an array of integers arr, you’re asked to calculate for each index i the product of all integers except the integer at that index (i.e. except arr[i]). Implement a function arrayOfArrayProducts that takes an array of integers and returns an array of the products.
  3.  
  4. Solve without using division and analyze your solution’s time and space complexities.
  5.  
  6. Examples:
  7.  
  8. input: arr = [8, 10, 2]
  9. output: [20, 16, 80] # by calculating: [10*2, 8*2, 8*10]
  10.  
  11. input: arr = [2, 7, 3, 4]
  12. output: [84, 24, 56, 42] # by calculating: [7*3*4, 2*3*4, 2*7*4, 2*7*3]
  13. Constraints:
  14.  
  15. [time limit] 5000ms
  16.  
  17. [input] array.integer arr
  18.  
  19. 0 ≤ arr.length ≤ 20
  20. [output] array.integer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement