← Back to Data Structures & Algorithms
Question 554
Subarray Sums By Brute Force
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
Sign in to use hintsTopics:
Data Structures & AlgorithmsBig-O
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.