100% FASTER CPP SOLUTION || DP || EXPLAINED
\nclass Solution {\npublic:\n    \n        \n//     EXPLANATION:\n    \n//     Took two Dps.\n\n//     1st dp for storing the number of substrings where the las
```\nclass Solution {\npublic:\n    \n        \n//     EXPLANATION:\n    \n//     Took two Dps.\n\n//     1st dp for storing the number of substrings where the last character i.e s[i-1]=t[j-1]\n//     2nd dp for storing the number of exactly 1 diff char ending with s[i-1]\n    \n//     now if s[i-1]==t[j-1], then dp1[i][j]=dp1[i-1][j-1]+1 and dp2[i][j]=dp2[i-1][j-1]\n//     else if s[i-1]!=t[j-1], then dp1[i][j]=0 and dp2[i][j]=1+dp1[i-1][j-1]\n//     add the ans with dp2[i][j]\n    \n//     return ans\n    \n    #define ll long long \n    int countSubstrings(string s, string t) {\n        ll n=s.length();\n        ll m=t.length();\n        ll dp1[n+1][m+1],dp2[n+1][m+1];\n        for(ll i=0;i<n;i++){\n            dp1[i][0]=0; dp2[i][0]=0;\n        }\n        for(ll i=0;i<m;i++){\n            dp1[0][i]=0; dp2[0][i]=0;\n        }\n        ll ans=0;\n        for(ll i=1;i<n+1;i++){\n            for(ll j=1;j<m+1;j++){\n                if(s[i-1]==t[j-1]){\n                    dp1[i][j]=1+dp1[i-1][j-1];\n                    dp2[i][j]=dp2[i-1][j-1];\n                    ans+=dp2[i][j];\n                }\n                else{\n                    dp1[i][j]=0;\n                    dp2[i][j]=1+dp1[i-1][j-1];\n                    ans+=dp2[i][j];\n                }\n            }\n        }\n        return ans;\n    }\n    \n    // KINDLY DO UPVOTE IF YOU LIKE THE EXPLANATION :)\n};\n```
['Dynamic Programming']