Wrong asnwer on submit

my code is giving wrong answer please review it :- https://ide.codingblocks.com/s/292786

while(t--)
    {
        cin>>s;
        ms(previous_count,-1);
        n=strlen(s);
        ms(dp,0);
        dp[0]=1;
        previous_count[s[0]]=0;
        f(i,1,n)
        {
          dp[i]=(2*dp[i-1])%mod;
          if(previous_count[s[i-1]]!=-1)
            dp[i]=(dp[i]-dp[previous_count[s[i-1]]-1]+mod)%mod;   // mod add karna h verna -ve meh chale jayega
        previous_count[s[i-1]]=i;
        }

        cout<<dp[n]<<endl;
    }

https://hack.codingblocks.com/app/contests/1288/1101/problem check editorial code from here