Skip to content

Instantly share code, notes, and snippets.

@niteshghn
Created January 22, 2020 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niteshghn/6a2d6b4c673d1cbf4516891b3197563f to your computer and use it in GitHub Desktop.
Save niteshghn/6a2d6b4c673d1cbf4516891b3197563f to your computer and use it in GitHub Desktop.
#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