Recursive Digit Sum

  • + 0 comments

    Hey 7ovana,

    I am try to do the code as below. But not pass all the test and shows that time exceed. Any idea why this approach is slower than yours, please?

    def superDigit(n, k):
        if len(n) == 1:
            return n
        
        n = n * k 
        
        while len(n) > 1:
            n = superDigit_helper(n)
        return n
    
    def superDigit_helper(n):
        return  str(sum(map(int, n)))