2
* @param {string[]} words8
this.children = new Map();13
var minimumLengthEncoding = function (words) {14
let minEncodingLength = 0;15
const sortedWords = words.sort((a, b) => a.length - b.length);17
const buildTrie = (root, word, index) => {18
// This means we reached to the end of word, so mark it as a word and compute encoding length20
minEncodingLength += word.length + 1;25
const character = word[index];26
// If we do not have a char in children, create a node and add it under root27
if (!root.children.has(character)) {28
const node = new Trie(character);29
root.children.set(character, node);30
buildTrie(node, word, index - 1);34
const node = root.children.get(character);35
// Remove the common suffix length considered before since it would be covered as a part of current word traversal38
minEncodingLength -= word.length - index + 1;41
buildTrie(node, word, index - 1);44
const root = new Trie();45
for (const word of sortedWords) {46
buildTrie(root, word, word.length - 1);49
return minEncodingLength;