My code for the above mentioned problem passes only 1 test case. I am not sure what am I doing wrong. Please help!!
My code : https://ide.codingblocks.com/s/461721
My code for the above mentioned problem passes only 1 test case. I am not sure what am I doing wrong. Please help!!
My code : https://ide.codingblocks.com/s/461721
It was cause of not taking modulus properly. You have to take it like this
dp[i] = ( (2%mod) * (dp[i - 1] % mod))%mod;
dp[i] = (dp[i] - dp[max_char[str[i - 1]]] + mod) % mod;
To avoid overflow
here is your corrected code, with comments
if this solves your doubt please mark it as resolved