let's say you get a number n, and a length k.
What you have to do is first turn n into a list of numbers, and then use a sliding window of size k where at each step you add the next number, and substract the first one in the sliding window, and keep track of the max_sum so you can return it at the end.
The function would look something like this
def altsum_digits(n, k):
list_n = [int(x) for x in str(n)]
max_sum = sum(list_n[:k])
for i in range(k, len(list_n)):
current_sum = current_sum + list_n[i] - list_n[i - k]
max_sum = max(current_sum, max_sum)
return max_sum
It's an O(n) solution, so it's a lot better than generating all sublists of size k. Hope it helps!