about | help | code help+videos | done | prefs |
Write a program that finds the "running product" of an input array of integers. The running product is found by finding the product of each pair of adjacent numbers in the array to make a new array. Then this process is repeated with the new array, so each pair of adjacent numbers has its product found and is placed in a new array. This process is continued until a single number is obtained. Return that single number as the result. Note that these running products can get very big very fast, so the return type is 'long' instead of 'int'. Here are some examples: {5,2,-3,1} becomes {10,-6,-3} (because 5*2=10, 2*(-3)=-6, and (-3)*1=-3) then {10,-6,-3} becomes {-60,18} (because 10*(-6)=-60, and (-6)*(-3)=18) then finally {-60,18} becomes -1080 (because (-60)*18=-1080) so the result is -1080. Likewise {4,2,7} becomes {8,14} which then becomes {112} so the result is 112. Notice that the order matters. {2,7,4} becomes {14, 28} which then becomes {392} so the result is 392. So changing the order gave a different result. You may choose to use recursion or not. There are good solutions either way. Keep in mind that your solution will need to deal with large integer values (long) and that your solution must not time-out on the given test data. nov3_2017_HL_runningProduct([1, 2, 1]) → 4 nov3_2017_HL_runningProduct([2, 1, 1, 1, 1]) → 2 nov3_2017_HL_runningProduct([1, 1, 2, 1, 1]) → 64 ...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: 410
Copyright Nick Parlante 2017 - privacy