From c768ba55262ae0d3ce69796ab419fd9cff18a521 Mon Sep 17 00:00:00 2001 From: agarwalgeetika2000 <39965675+agarwalgeetika2000@users.noreply.github.com> Date: Sun, 10 May 2020 00:13:45 +0530 Subject: [PATCH] Task 8 --- 17EGICS031_ARRAY_8 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 17EGICS031_ARRAY_8 diff --git a/17EGICS031_ARRAY_8 b/17EGICS031_ARRAY_8 new file mode 100644 index 0000000..9293d66 --- /dev/null +++ b/17EGICS031_ARRAY_8 @@ -0,0 +1,23 @@ + Given an array of positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should not + #be adjacent in the array. + + +list=[] +n=int(input("Enter the size:")) +maxi=0 +for i in range(n): + ele=int(input()) + list.append(ele) +inc=0 +exc=0 +for i in range(n): + if exc > inc: + new_exc = exc + else: + new_exc = inc + inc = exc + list[i] + exc = new_exc +if exc > inc: + print (exc) +else: + print (inc)