For input , let be the largest sum of a nonempty contiguous block ending at . The recurrence relation and is exact: an optimal block either starts at or extends an optimal block ending at . The answer is . Keeping only the current and best value gives linear time complexity and constant extra space complexity.

Articles by others on the same topic (0)

There are currently no matching articles.