Max Winning Streak Game Points
Coding Problem Keys
Max Winning Streak Game Points
Problem Statement
Alok is playing N round of card games with his friend Brinda. He gets positive or negative based on whether he won or lost in a specific round. Alok can also get zero points in case of a tie.
Given the points obtained in N rounds, the program must print the maximum sum of points obtained in any of the winning streak sequence.
Boundary Condition(s)
3 <= N <= 100
-100 <= P(i) <= 100
Input Format
The first line contains N.
The second line contains the points P(i), i = 1 to N with the points separated by a space.
Output Format
The first line contains M which represents the maximum number of points obtained in any of the winning sequence.
Example Input/Output 1
Input
7
9 2 3 -1 1 2 4
Output
14
Example Input/Output 2
Input
15
11 20 6 7 -4 2 -5 15 8 3 16 8 3 -1 -2
Output
53
Example Input/Output 3
Input
5
-1 -2 -4 -9 -3
Output
0
Note: Max Execution Time Limit: 5000 millisecs
Solution
Programming Language: Python 3 Language
n=int(input())
l=list(map(int,input().split()))
k=[0,];s=[]
for i in range(n):
if l[i]>0:
s.append(l[i])
if i==n-1:
k.append(sum(s))
if l[i]<=0 and s!=[]:
k.append(sum(s))
s=[]
print(max(k))
# Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments