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.
Like others said, converting str to int and doing calculations won't work for the input test cases and Python string conversion defaults.
Doing digit by digit conversions avoids the problem.
My solution:
defsuperDigit(n,k):# Write your code heresum_of_digits=0fordigitinn:sum_of_digits+=int(digit)sum_of_digits*=kifsum_of_digits<10:returnsum_of_digitselse:returnsuperDigit(str(sum_of_digits),1)
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 →
Like others said, converting str to int and doing calculations won't work for the input test cases and Python string conversion defaults.
Doing digit by digit conversions avoids the problem.
My solution: