Q#6: Multiply array values, return the remainder
Published in
Sep 10, 2020
Suppose you’re given an array of varying length containing multiple #s, and a number x. Using these inputs, write a short program in Python find the remainder of the array multiplication divided by x.
For example:
#Given the following
array = [5,2,4,1,5]
x = 6#We would calculate output as such:
5*2*4*1*5 = 200 % 6 = 2
-Credit: erik@interviewqs.com
Answer:
array = input()
mult = 1
x = len(array)
for i in array:
mult = mult*i
print(mult % x)