Pls provide soln

pls provide soln iam not able to solve by dp

Following the recurrence:

dp[i]=(dp[i]-dp[previous_count[str[i-1]]-1]+mod)%mod;

i have seen the soln in gfg not able to understand thre nor here plas provide soln with explanation

there are two options:
you take the element or u do not take the element. Now, think if u come at a character which has been already there before the current position then, there is a case which u have already calculated previously that u will not take that character. Now, if u are at the same character and u choose that i will not take this character then u need to subtract the previous ways of not selecting this character as this leads to the same result.