about | help | code help+videos | done | prefs |
Write a method that returns the sum of all the elements in 'nums' that are multiples of one or more of the numbers in 'mults'. Only count each element in 'nums' at most once, even if it is a multiple of more than one number in 'mults'. For example, if 'nums' is {15,3,17,22,30} and 'mults' is {3,5} you would return 48 since 15+3+30=48. Notice that 15 and 30 are multiples of both 3 and 5, but they are only added to the sum once. As preconditions you may assume that all integers in both arrays are greater than or equal to 2. Look at the test data for further examples. test2024_12_12_SLHL_addIfMult([71, 81, 91], [30, 50]) → 0 test2024_12_12_SLHL_addIfMult([20, 30, 70, 75, 89, 95, 120], [30]) → 150 test2024_12_12_SLHL_addIfMult([14, 23, 27, 500, 1500, 2000, 2020, 2900], [1000]) → 2000 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 290
Copyright Nick Parlante 2017 - privacy