Loading problem…
Pick the tightest time complexity.
function bfs(graph, start) { const seen = new Set([start]) const queue = [start] for (let i = 0; i < queue.length; i++) { const node = queue[i] for (const next of graph[node]) { if (!seen.has(next)) { seen.add(next) queue.push(next) } } } }