Maximum subarray sum

Write codeEasy10 minAmazon and Google style

Your task

After a long road trip you log one mood score per day, an integer that can be negative on rough days. You want to find the most enjoyable stretch of the trip: the consecutive block of one or more days whose scores add up to the largest total. Given the daily scores in order, return that maximum total. The list is non-empty. For example, [-2, 4, -1, 5] gives 8 for the stretch [4, -1, 5].

Examples

best_trip_stretch(mood: list[int]) -> int
Example 1
Inputbest_trip_stretch([-2, 4, -1, 5])
Output8
Example 2
Inputbest_trip_stretch([-3, -1, -2])
Output-1