Error in Problem 3 - longst non repetetive substring(beginner problem)

Hi, I am a beginner and I did this on my own,and my code is

    Z = []
    K = 0
    M = 0
    for i in s:
        if i in Z:
            Z.clear()
            if K > M or K == M:
                M = K
                K = 0
            else:
                K = 0
            Z.append(i)
            K += 1 


        else:
            Z.append(i)
            K += 1
    return M

so like for one of the test cases
like for input = ' '
my code returned = 0
but expected result = 1
further when i substituted an if case for ' ':return 1 ,the error returned was
expected = 0
returned = 1
so i am unable to understand the problem behind the code,
if someone can please explain me,it woud be really helpfull.
Thank you in advance. :D

Comments (0)