Menu Close

Return the size of the longest sub-string

Given the string s, return the size of the longest sub-string containing each vowel an even number of times. That is, ‘a’,’e’,’i’,’o’,’u’ must appear an even number of times.

Input : S = ‘eleetminicoworoep’
Output : 13

def dist(S,Z):
    p=S.find(Z)
    q=S[::-1].find(Z)
    return S[p+1:] if p < q else S[:-q-1]

def vowels(X):
    temp=None
    dict={'a':0,'e':0,'i':0,'o':0,'u':0}
    flag=0
    for i in X:
        if i in dict:
            dict[i]+=1
    for i in dict:
        if (dict[i] % 2 != 0):
            temp=dist(X,i)
            flag+=1
            break
    if flag!=0:
        X=temp
        return vowels(X)
    else:
        return X

S=input('Enter the String : ')
print(len(vowels(S)))

Input_1:
Enter the String : eleetminicoworoep
Output:
13


Input_2:
Enter the String : fcukthecode
Output:
3


Input_3:
Enter the String : jojos bizarre adventure
Output:
12


Input_4:
Enter the String : bcbcbc
Output:
6


Morae Q!