Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

max sum slice python 1 - autopilot

def max_sum_slice(xs):
    best_sum, best_start, best_end = 0, None, None

    for i, x in enumerate(xs):
        if best_start is None or best_sum < x + best_sum:
            best_sum = x + best_sum
            best_start = i
            best_end = i
        elif best_sum > x + best_sum:
            best_sum = x + best_sum
            best_end = i

    return best_sum, best_start, best_end
Source by copilot.github.com #
 
PREVIOUS NEXT
Tagged: #max #sum #slice #python #autopilot
ADD COMMENT
Topic
Name
7+3 =