I am working through the Max Multiple challenge on Code Signal:
Given a
divisor
and abound
, find the largest integerN
such that:
N
is divisible bydivisor
.N
is less than or equal tobound
.N
is greater than 0. It is guaranteed that such a number exists.Example
For
divisor = 3
andbound = 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.