CJCoding With Joseph
15free / daySign inCreate account

Subarray Sums By Brute Force

Write max_subarray_brute(values: list[int]) -> int that returns the largest sum of any run of one or more adjacent elements, the brute-force way: the outer loop fixes a start, the inner loop extends an end one step at a time while a running total holds the sum of the current run, and best keeps the largest total seen. The list has at least one value, and the answer may be negative. This is O(n squared). Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of space-separated integers; the tests print the value your function returns.

Expected Output:

6

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
Data Structures & AlgorithmsBig-O
📥 Auto-Input:
-2 1 -3 4 -1 2 1 -5 4\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.