Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions 17EGICS031_ARRAY_8
Original file line number Diff line number Diff line change
@@ -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)