Count Subsequences

Can you please explain why adding mod in line 19 was important?

This to avoid large numbers and to avoid integer overflow.
Values very large of order 10^10 or greater cannot be stored in an integer variable so we perform that step

@pratyush63 if don’t mind can you explain
dp[i] = (dp[i] - dp[last[s[i - 1]]] + mod) % mod;
in Details of mod here with a example why is so important