Java Solution in more efficient  way
\nclass Solution {\n\tpublic int countSubstrings(String s, String t) {\n\t\tint r = s.length();\n\t\tint c = t.length();\n\t\tint[][] dp = new int[r][c];\n\t\ti
```\nclass Solution {\n\tpublic int countSubstrings(String s, String t) {\n\t\tint r = s.length();\n\t\tint c = t.length();\n\t\tint[][] dp = new int[r][c];\n\t\tint resp = 0;\n\t\tfor (int i = 0; i < r; i++) {\n\t\t\tfor (int j = 0; j < c; j++) {\n\t\t\t\tif (s.charAt(i) != t.charAt(j))\n\t\t\t\t\tdp[i][j] = 1;\n\n\t\t\t\tint p = i;\n\t\t\t\tint q = j;\n\t\t\t\tint count = 0;\n\t\t\t\twhile (p >= 0 && q >= 0) {\n\t\t\t\t\tcount = count + dp[p][q];\n\n\t\t\t\t\tif (count > 1)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tif (count == 1)\n\t\t\t\t\t\tresp = resp + 1;\n\t\t\t\t\tp--;\n\t\t\t\t\tq--;\n\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\n\t\treturn resp;\n\t}\n}\n```
[]