Generation

generate functionSat, 12 Nov 2022

calculate the largest sum of integers in a string of numbers

def max_sum_in_string(numbers): max_sum = 0 numbers_list = numbers.split(" ") numbers_list = list(map(int, numbers_list)) for i in range(0, len(numbers_list)): for j in range(i, len(numbers_list)): sum = 0 for k in range(i, j+1): sum = sum + numbers_list[k] if(sum > max_sum): max_sum = sum return max_sum max_sum_in_string("-4 3 -2 1")

Questions about programming?Chat with your personal AI assistant