Write a function solution that given a three digit integer N and Integer K, returns the maximum possible three digit value that can be obtained by performing at most K increases by 1 of any digit in N
def max_int(n, k):
d1 = n%10
d2 = (n//10) % 10
d3 = (n//100) % 10
if d3 > 9:
return
k3 = min(k, 9-d3)
d3 += k3
k -= k3
k2 = min(k, 9-d2)
d2 += k2
k -= k2
k1 = min(k, 9-d1)
d1 += k1
return d3*100 + d2*10 + d3
def main():
n = int(input())
k = int(input())
print(max_int(n, k))
if __name__ == "__main__":
main()
Comments
Leave a comment