Help me in solving SNELECTP problem

My issue

what is the mistake in my approach

My code

t=int(input())
for _ in range(t):
    s=input()
    snakes=s.count('s')
    mongoose=s.count('m')
    for i in range(len(s)):
        if s[i]=='m':
            if i>0 and s[i-1]=='s':
                snakes-=1
            elif i<len(s)-1 and s[i+1]=='s':
                snakes-=1
    if snakes>mongoose:
        print("snakes")
    elif snakes<mongoose:
        print("mongooses")
    else:
        print("tie")

Learning course: Greedy Algorithms
Problem Link: Snakes, Mongooses and the Ultimate Election Practice Problem in Greedy Algorithms - CodeChef

@sivaramaraju21
plzz refer the following code

T = int(input())
for _ in range(T):
    s = input()
    n = len(s)
    killed = [False] * n

    for i in range(n):
        if s[i] == 'm':
            if i - 1 >= 0 and s[i - 1] == 's' and not killed[i - 1]:
                killed[i - 1] = True
                continue
            if i + 1 < n and s[i + 1] == 's':
                killed[i + 1] = True

    snakes = 0
    mongooses = 0

    for i in range(n):
        if s[i] == 's' and not killed[i]:
            snakes += 1
        if s[i] == 'm':
            mongooses += 1

    ans = "tie"
    if snakes > mongooses:
        ans = "snakes"
    elif mongooses > snakes:
        ans = "mongooses"

    print(ans)