Created
September 5, 2015 08:45
-
-
Save shashisp/4279be638d797d17fb5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = raw_input().split(',') | |
s = map(int, s) | |
max_sum = 0 | |
max_so_far = 0 | |
left_i = 0 | |
right_i = 0 | |
#check all elements in the given list are positive | |
def all_positive(s): | |
return filter(lambda x: x > 0, s) == s | |
#check all elements in the given list are negative | |
def all_negative(s): | |
return filter(lambda x: x < 0, s) == s | |
if all_negative(s): | |
print max(s) | |
elif all_positive(s): | |
print ','.join(map(str, s)) | |
else: | |
for i in range(1, len(s)): | |
if max_sum < 0: | |
left_i = i | |
max_sum = s[i] | |
else: | |
max_sum += s[i] | |
if (max_sum> max_so_far): | |
right_i = i | |
max_so_far = max_sum; | |
s = s[left_i:right_i+1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment