C++ | short O{n*m*min(n,m)} solution with comments
\nclass Solution {\npublic:\n    int countSubstrings(string s, string t) {\n        int n=s.size(),m=t.size(),ans=0;\n        for(int i=0; i<n; i++){\n         
```\nclass Solution {\npublic:\n    int countSubstrings(string s, string t) {\n        int n=s.size(),m=t.size(),ans=0;\n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                //index to start comaparing the subarrays as given in the condition of exactly one character differing\n                if(s[i]!=t[j]){\n                    int c1=0,c2=0,iprev=i-1,inext=i+1,jprev=j-1,jnext=j+1;\n                    //counting the characters before the current one\n                    while(iprev>=0 and jprev>=0 and s[iprev]==t[jprev]){\n                        c1++; iprev--; jprev--;\n                    }\n                    //counting the characters after the current one\n                    while(inext<n and jnext<m and s[inext]==t[jnext]){\n                        c2++; inext++; jnext++;\n                    }\n                    //c1*c2 indicates number of subarrays created using all combinations from left and right sides of current\n                    //c1 indicates just the subarrays to the left side\n                    //c2 indicates just the subarrys to the right side\n                    //adding extra 1 for the single current character subarray\n                    ans+=c1*c2+c1+c2+1;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
[]