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.
defsuperDigit(n:str,k:int)->int:# sum digits of 'n' first and then multiply by k, # instead of summing up digits of int(string * k):p=sum(list(map(int,list(n))))*kwhilep>10:#sameaslen(str(p))!=1p=sum(list(map(int,list(str(p)))))# can also use sum(int(digit) for digit in str(p))returnp
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
Python solution: