Maximum subarray
HardGiven an array of integers, find the maximum sum of any subarray within the array.
Some examples:
max_sum([1, 9, 2])returns12from the subarray[1, 9, 2]max_sum([-2, 5, -1, 4])returns8from the subarray[5, -1, 4]max_sum([-1, 3, -2])returns3from the subarray[3]
Note that a subarray implies that the numbers must be contiguous in the array.
Solution
7 Essential Arrays Coding Interview Problems
Master Arrays by trying the coding challenges below.
- 1.Trade stock onceEasy
- 2.AdditionEasy
- 3.Find the smallestEasy
- 4.Sort colorsMedium
- 5.Reorganize numbersHard
- 6.Maximum subarrayHard
- 7.Container of waterHard
