Largest Sum

Report a typo

Implement a function that calculates the largest k digits of n, where n and k are both non-negative integers. Given n=2018n = 2018 and k=2k = 2, the largest kk digits in nn are 2 and 8 respectively, if we sum 2 and 8, we get the desired output 10.

There are many ways to solve this task, but please try to solve using recursion.

Sample Input 1:

2018
2

Sample Output 1:

10
Write a program in Python 3
def sum_largest(n, k):
pass

n = int(input())
k = int(input())

print(sum_largest(n, k))
___

Create a free account to access the full topic