MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / ladderLength

Function ladderLength

javascript/0127-word-ladder.js:9–22  ·  view source on GitHub ↗
(beginWord, endWord, wordList)

Source from the content-addressed store, hash-verified

7 * @return {number}
8 */
9var ladderLength = function (beginWord, endWord, wordList) {
10 const [queue, wordSet, seen] = [
11 new Queue([[beginWord, 1]]),
12 new Set(wordList),
13 new Set([beginWord]),
14 ];
15
16 return bfs(
17 queue,
18 wordSet,
19 seen,
20 endWord,
21 ); /* Time O(ROWS * COLS) | Space O(ROWS * COLS) */
22};
23
24const bfs = (queue, wordSet, seen, endWord) => {
25 while (!queue.isEmpty()) {

Callers

nothing calls this directly

Calls 1

bfsFunction · 0.70

Tested by

no test coverage detected