10 views2 pages

Document Summary

Given an array of integers, a of length n, find out the maximum sum sub-array of non negative numbers from. The sub-array should be contiguous i. e. , a sub-array created by choosing the second and fourth element and skipping the third element is invalid. Maximum sub-array is defined in terms of the sum of the elements in the sub-array. If there is a tie, then compare with segment"s length and return segment which has maximum length. If there is still a tie, then return the segment with minimum starting index. The first and the only argument of input contains an integer array a, of length n. Return an array of integers, that is a subarray of a that satisfies the given conditions. A = [1, 2, 5, -7, 2, 3] The two sub-arrays are [1, 2, 5] [2, 3]. The answer is [1, 2, 5] as its sum is larger than [2, 3]. The three sub-arrays are [10], [2, 3], [100].

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents