Ad

Refactored, turned into one-liner, using list comprehension.

Code
Diff
  • def max_sequence(arr):
        # Code to find maximum sum of subarray
    	return max(
            [sum(arr)] + 
            [sum(arr[j:j+i]) for i in range(len(arr)) for j in range(len(arr) - i + 1)]
        )
    • def max_sequence(arr):
    • # Code to find maximum sum of subarray
    • sum_b = sum(arr)
    • for i in range(len(arr)):
    • for k in range(len(arr)-i+1):
    • sum_c = sum(arr[k:k+i])
    • if sum_c > sum_b: sum_b = sum_c
    • return(sum_b)
    • return max(
    • [sum(arr)] +
    • [sum(arr[j:j+i]) for i in range(len(arr)) for j in range(len(arr) - i + 1)]
    • )