1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4925],{4925:function(n,t,e){e.r(t),t.default="## Exercise: Maximum Subarray Sum\n### Instructions\nWrite a function `max_subarray_sum(lst)` that takes a list `lst` of integers, and returns the maximum sum of a contiguous subarray in the list.\n\nAssume that the input list `lst` will always contain at least one integer.\n\n### Examples\n```\n>>> max_subarray_sum([1, -2, 3, 4, -1, 2, 1, -5, 4])\nOutput: 10\n```\n```\n>>> max_subarray_sum([-2, -3, 4, -1, -2, 1, 5, -3])\nOutput: 7\n```\n```\n>>> max_subarray_sum([1, 2, 3, 4, 5])\nOutput: 15\n```\n***\ndef max_subarray_sum(lst):\n max_current = max_global = lst[0]\n for i in range(1, len(lst)):\n max_current = max(lst[i], max_current + lst[i])\n if max_current > max_global:\n max_global = max_current\n return max_global\n\n***\ndef max_subarray_sum(lst):\n pass\n***\ndef test_case_1():\n return [\n [[1, -2, 3, 4, -1, 2, 1, -5, 4]], \n 9\n ]\n\ndef test_case_2():\n return [\n [[-2, -3, 4, -1, -2, 1, 5, -3]], \n 7\n ]\n\ndef test_case_3():\n return [\n [[1, 2, 3, 4, 5]], \n 15\n ]\n\ndef test_case_4():\n return [\n [[-1, -2, -3, -4, -5]], \n -1\n ]\n\ndef test_case_5():\n return [\n [[-1, 2, -3, 4, -5]], \n 4\n ]\n\ndef test_case_6():\n return [\n [[-1, -2, -3, -4, 5]], \n 5\n ]\n\ndef test_case_7():\n return [\n [[-1, -2, -3, -4, -5, 0]], \n 0\n ]\n\ntest_cases = [test_case_1, test_case_2, test_case_3, test_case_4, test_case_5, test_case_6, test_case_7]"}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.