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.
I can't figure out how to fix this code. It only works for 2 tests. For the ones it fails it's usually just one more move than expected
defdownToZero(n):moves=0whilen!=0:a=1b=1ifn==1:n-=1moves+=1break# calculate factors until a < bfornuminrange(n-1,1,-1):ifn%num==0:a=numb=n// numifa<b:breakif(a==1)or(a==n):n-=1else:n=max(a,b)moves+=1returnmoves
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 →
I can't figure out how to fix this code. It only works for 2 tests. For the ones it fails it's usually just one more move than expected