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,k):# Base case: If n is already a single-digit number, return it as the super digitiflen(n)==1:returnint(n)# Calculate the sum of the digits of n multiplied by kadded=sum(int(i)foriinn)*k# Recursive call: with the sum converted to string and k set to 1# since repeated multiplication is only needed once returnsuperDigit(str(added),1)
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
Python solution
Explaining the code:
"@nemat-al/recursive-digit-sum-hackerrank-python-db446d084a89">https://medium.com/@nemat-al/recursive-digit-sum-hackerrank-python-db446d084a89"