Using Trie, in Javascript
\n\n# Code\n\nclass TrieNode {\n    constructor() {\n        this.children = new Map()\n        this.count = 0\n    }\n}\n\nclass Trie {\n    constructor() {\n 
\n\n# Code\n```\nclass TrieNode {\n    constructor() {\n        this.children = new Map()\n        this.count = 0\n    }\n}\n\nclass Trie {\n    constructor() {\n        this.root = new TrieNode()\n    }\n\n    insert(word) {\n        let curr = this.root\n        for (const char of word) {\n            if (!curr.children.has(char)) {\n                curr.children.set(char, new TrieNode())\n            }\n            curr = curr.children.get(char)\n        }\n        curr.count++\n    }\n}\n\n/**\n * @param {string} s\n * @param {string} t\n * @return {number}\n */\nvar countSubstrings = function (s, t) {\n    const trie = new Trie()\n\n    for (let i = 0; i < t.length; i++) {\n        let subStr = \'\'\n        for (let j = i; j < t.length; j++) {\n            subStr += t[j]\n            trie.insert(subStr)\n        }\n    }\n\n    let count = 0\n    for (let i = 0; i < s.length; i++) {\n        let subStr = \'\'\n        for (let j = i; j < s.length; j++) {\n            subStr += s[j]\n            count += countHelper(trie, subStr)\n        }\n    }\n\n    return count\n};\n\nfunction countHelper(trie, subStr) {\n    let count = 0\n    dfs(trie.root, 0, 0)\n    return count\n\n    function dfs(node, d, i) {\n        if (d > 1) return\n        if (i == subStr.length) {\n            if (d == 1) count += node.count\n            return\n        }\n\n        const children = node.children\n        for (const [char, child] of children) {\n            dfs(child, d + (char != subStr[i]), i + 1)\n        }\n    }\n}\n```
['JavaScript']