From aaaf0d74bd5b743fe7310d453fb220437bea0206 Mon Sep 17 00:00:00 2001 From: Hakan Date: Thu, 16 Jul 2020 17:19:38 +0200 Subject: [PATCH] max sequence --- 027_max_sum_sub.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 027_max_sum_sub.py diff --git a/027_max_sum_sub.py b/027_max_sum_sub.py new file mode 100644 index 0000000..c550d2c --- /dev/null +++ b/027_max_sum_sub.py @@ -0,0 +1,14 @@ +arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4] # should be 6: [4, -1, 2, 1] + + +# def maxSequence(arr): +# return max([sum(arr[i:j]) for i in range(len(arr)+1) for j in range(len(arr)+1)]) +# print(maxSequence(arr)) + +def maxSequence(arr): + summ=[] + for j in range(len(arr)+1): + for i in range(len(arr)+1): + summ.append(sum(arr[i:j])) + return max(summ) +print(maxSequence(arr)) \ No newline at end of file