In this Kata, you will be given an integer `n` and your task will be to return `the largest integer that is <= n and has the highest digit sum`.
For example:
```
solve(100) = 99. Digit Sum for 99 = 9 + 9 = 18. No other number <= 100 has a higher digit sum.
solve(10) = 9
solve(48) = 48. Note that 39 is also an option, but 48 is larger.
```
Input range is `0 < n < 1e11`
More examples in the test cases.
Good luck!
def solve(n):
    b = [int(str(n)[0]) - 1] + [9 for x in str(n)[1:]]
    digsum = sum(b)
    if digsum <= sum([int(x) for x in str(n)]):
        return n
    for i in range(len(str(n))-1, -1, -1):
        a = [int(x) for x in str(n)[:i]] + [int(str(n)[i]) - 1] + [9 for x in str(n)[i+1:]]
        print((i,a))
        if sum(a) == digsum:
            break
    return int("".join([str(x) for x in a]))

def solve(n):
    b = [int(str(n)[0]) - 1] + [9 for x in str(n)[1:]]
    digsum = sum(b)
    if digsum <= sum([int(x) for x in str(n)]):
        return n
    for i in range(len(str(n))-1, -1, -1):
        a = [int(x) for x in str(n)[:i]] + [int(str(n)[i]) - 1] + [9 for x in str(n)[i+1:]]
        print((i,a))
        if sum(a) == digsum:
            break
    return int("".join([str(x) for x in a]))
