We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My solution in python,
I had timeout before making unique values with set(newVals)
defdownToZero(n):# Write your code hereops=0vals=[n]whileTrue:newVals=[]forvalinvals:ifval<=3:returnops+valdivisors=maxDivisors(val)ifdivisors!=[]:fordivindivisors:newVals.append(div)newVals.append(val-1)ops+=1vals=sorted(list(set(newVals)))defmaxDivisors(n):div=int(math.sqrt(n))divisors=[]whilediv>=2:ifn%div==0:divisors.append(int(n/div))div-=1returndivisors
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Down to Zero II
You are viewing a single comment's thread. Return to all comments →
My solution in python, I had timeout before making unique values with
set(newVals)