• + 0 comments

    Python 3 solution... Needed a bit of an optimization to avoid memory issue (e.g. the initial_super_digit calculation).

    def _super_digit(n):
        if len(str(n)) == 1:
            return n
        return _super_digit(sum([int(c) for c in str(n)]))
    
    def superDigit(n, k):
        initial_super_digit = _super_digit(n)
        return _super_digit(initial_super_digit * k)