(words, graph, frequencyMap)
| 36 | }; |
| 37 | |
| 38 | var canBuildGraph = (words, graph, frequencyMap) => { |
| 39 | for (let index = 0; index < words.length - 1; index++) { |
| 40 | const [word1, word2] = [words[index], words[index + 1]]; |
| 41 | const minLength = Math.min(word1.length, word2.length); |
| 42 | |
| 43 | const isWord1Longer = word2.length < word1.length; |
| 44 | const isPrefix = isWord1Longer && word1.startsWith(word2); |
| 45 | |
| 46 | if (isPrefix) return false; |
| 47 | |
| 48 | for (let j = 0; j < minLength; j++) { |
| 49 | const [char1, char2] = [word1[j], word2[j]]; |
| 50 | |
| 51 | const isEqual = char1 === char2; |
| 52 | if (isEqual) continue; |
| 53 | |
| 54 | graph.get(char1).push(char2); |
| 55 | frequencyMap.set(char2, frequencyMap.get(char2) + 1); |
| 56 | |
| 57 | break; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return true; |
| 62 | }; |
| 63 | |
| 64 | const bfs = (queue, frequencyMap, graph, buffer) => { |
| 65 | while (!queue.isEmpty()) { |
no test coverage detected