Created
January 22, 2020 09:12
-
-
Save niteshghn/6a2d6b4c673d1cbf4516891b3197563f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#language = python3 | |
## return a list of steps | |
def findSmallestMult(arr,num): | |
out = [1] | |
# sort the input array | |
arr.sort() | |
# remove 1 from array as we are starting from 1 | |
if arr[0]==1: | |
arr.pop(0) | |
# find out all the multiple of given target num in array | |
mults = list(filter(lambda x:num%x==0, arr)) | |
# if there don't exists a multiple of num | |
# that means we can not reach to num so return [1] | |
if not mults: | |
return out | |
for i in range(len(arr)-1,-1,-1): | |
if arr[i]==num: | |
out.append(a[i]) | |
break | |
else: | |
if (num//arr[i]) in mults: | |
out+=[num//arr[i],num] | |
break | |
return out | |
print (findSmallestMult([2,3,4],12)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment