CHEFZOT - Editorial

Better than editorial :grin:

For the following solution I get AC :

n = int(input())
    
li = list(map(int,input().split()))
count = 0
maximum = 0
i = 0
while i < len(li):
        
    if li[i]>0:
        count = count+1
        if maximum <= count:
            maximum = count
    else:
        count = 0
        
    i+=1
            
print(maximum)

For the following I get WA:

n = int(input())
    
li = list(map(int,input().split()))
count = 0
maximum = 0
i = 0
while i < len(li):
        
    if li[i]>0:
        count = count+1
    else:
        if maximum <= count:
            maximum = count
        count = 0
        
    i+=1
            
print(maximum)

Any Idea on what test case might the one with WA fail? Seems like the same code to me.

https://www.codechef.com/viewsolution/62074372

Here is a link to my solution in Python 3.6. I follow a different way to get to the solution but one of the test case seems to be failing. Can anyone help me find out what it might be

hey @shivamgutgutia,
Congrats on posting your first query!
Here is a test case in which give a wrong answer :point_down:

3
10 10 10

the correct answer is 3 but your code gives 1.

you are taking nums input as

nums=’ '.join(input().strip().split())

Remember that input() will cast the input as a string. Thus for above mention input, your nums will be “10 10 10”.
If you split this string with ‘0’ nums become [“1”, " 1", " 1"] .
Thanks.

1 Like

Oh yes. That was such a silly mistake. Thanks. I now understand where my code went wrong