Vowel anxiety-getting tle

for _ in range(int(input())):
length = int(input())
strvalue = input()
l=list(strvalue)
vowel = [‘a’, ‘e’, ‘i’, ‘o’, ‘u’]
n=0
for char in l:
n+=1
if char in vowel:
reversestr = strvalue[0:(n-1)]
strvalue = reversestr[::-1] + strvalue[n-1::]

print(strvalue)
1 Like

This is a brute force method. where you are reversing the string again and again whenever an vowel occurs.
Time complexity for this code is O(N*N). which is leading it to tle.
try to solve it in O(N) time.