I am working through the Max Multiple challenge on Code Signal:
Given a
divisorand abound, find the largest integerNsuch that:
Nis divisible bydivisor.Nis less than or equal tobound.Nis greater than 0. It is guaranteed that such a number exists.Example
For
divisor = 3andbound = 10, the output should bemaxMultiple(divisor, bound) = 9.The largest integer divisible by 3 and not larger than 10 is 9.
This is my attempt:
def maxMultiple(divisor, bound):
largest = 0
for i in range(0,bound):
if i % divisor == 0 and i <= bound:
largest = i
print(largest)
It passes on most tests but fails on these ones:
Input: divisor: 8
bound: 88
Output: null
Expected Output:88
Console Output:80
Input:divisor: 10
bound: 100
Output: null
Expected Output: 100
Console Output: 90
I am checking for the constraints in my if statement but it fails on these two cases. I do not understand why.