From dcfdf73a7f937e12470a585add4e6107ef942583 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sat, 19 Dec 2020 20:20:45 -0800 Subject: [PATCH] Separators --- data_structures/arrays/get_products_of_all_other_elements.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data_structures/arrays/get_products_of_all_other_elements.rb b/data_structures/arrays/get_products_of_all_other_elements.rb index b4a8a2f..e22dd1a 100644 --- a/data_structures/arrays/get_products_of_all_other_elements.rb +++ b/data_structures/arrays/get_products_of_all_other_elements.rb @@ -5,7 +5,9 @@ # each element at index `i` of the new array is the product of # all the numbers in the original array except the one at `i`. +# # 1. Brute force solution +# def calculate_products_of_all_other_elements(nums) products_other_elements = Array.new(nums.length, 1) @@ -22,8 +24,10 @@ end puts(calculate_products_of_all_other_elements([1, 2, 3])) +# # 2. O(n) time and space # Arrays - Get Products of all other elements in Ruby +# # Generates prefix products def build_prefix_products(nums)