-
Description basically refactored
Code 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)
Test Cases import codewars_test as test from solution import max_sequence .describe("Max Sequence Tests") def test_group(): .it("Case 1") def test_case_1(): test.assert_equals(max_sequence([0,1,2,3,4,5,6,7,8,9,10]), 55) test.assert_equals(max_sequence([-22,1,2,3,4,5,6,7,8,9,10]), 55) test.assert_equals(max_sequence([0,1,2,3,4,5,-6,7,8,9,10]), 43) test.assert_equals(max_sequence([0,0,0,0,0,0,0,0,0,99,-1, 23, 43]), 164) test.assert_equals(max_sequence([0] * 10), 0) test.assert_equals(max_sequence([-1] * 10), 0) test.assert_equals(max_sequence([1] * 10), 10)
Output:
-
Code - def max_sequence(arr):
- # Code to find maximum sum of subarray
l_a = len(arr)- sum_b = sum(arr)
for i in range(l_a):for k in range(l_a-i+1):- 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)
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
Please sign in or sign up to leave a comment.