Skip to content

Latest commit

 

History

History
20 lines (14 loc) · 585 Bytes

subarray_sum.markdown

File metadata and controls

20 lines (14 loc) · 585 Bytes

Problem

In computer science, the maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array of numbers (containing at least one positive number) which has the largest sum.

Example

For example, for the sequence of values −2, 1, −3, 4, −1, 2, 1, −5, 4; the contiguous subarray with the largest sum is 4, −1, 2, 1, with sum 6.

Exercise

Write a method that when given an array, return the biggest subarray and the sum, e.g.

biggest_subarray([−2, 1, −3, 4, −1, 2, 1, −5, 4]) # => [6, [4, −1, 2, 1]]