Q#6: Multiply array values, return the remainder

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)

--

--

Foundational Data Science: Interview Questions
Foundational Data Science: Interview Questions

Published in Foundational Data Science: Interview Questions

Data Science tutorial working through solutions to Data Science Interview Questions

Abish Pius
Abish Pius

Written by Abish Pius

Data Science Professional, Python Enthusiast, turned LLM Engineer