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.
Recursive Digit Sum
Recursive Digit Sum
Sort by
recency
|
810 Discussions
|
Please Login in order to post a comment
Python one-liner with recursion:
return n if k == 1 and n < 10 else superDigit(k * sum(int(d) for d in list(str(n))), 1)
Typescript Solution
def superDigit(n, k): # Calculate the initial sum for the repeated number num = str(sum(map(int, str(n))) * k)
`//Java solution with recursion:-
public static int superDigit(String n, int k) { if(n.length()==1) return Integer.parseInt(n);
`
There is no recursion here, checkout my 3 line solution: