-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path5_maxMultiple.go
46 lines (33 loc) · 918 Bytes
/
5_maxMultiple.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
Challenge: Max Multiple
https://codefights.com/arcade/code-arcade/intro-gates/HEsmEacHr2s9wahjr/description
Given a divisor and a bound, find the largest integer N such that:
N is divisible by divisor.
N is less than or equal to bound.
N is greater than 0.
It is guaranteed that such a number exists.
Example
For divisor = 3 and bound = 10, the output should be
maxMultiple(divisor, bound) = 9.
The largest integer divisible by 3 and not larger than 10 is 9.
Input/Output
[time limit] 4000ms (go)
[input] integer divisor
Guaranteed constraints:
2 ≤ divisor ≤ 10.
[input] integer bound
Guaranteed constraints:
5 ≤ bound ≤ 100.
[output] integer
The largest integer not greater than bound that is divisible by divisor.
**/
func maxMultiple(divisor int, bound int) int {
n := bound
for n > 0 {
if n % divisor == 0 {
return n
}
n--
}
return -1
}