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

Function findRedundantConnection

javascript/0684-redundant-connection.js:7–18  ·  view source on GitHub ↗
(edges)

Source from the content-addressed store, hash-verified

5 * @return {number[]}
6 */
7var findRedundantConnection = function (edges) {
8 const graph = new Array(1000 + 1).fill().map(() => []);
9
10 for (const [src, dst] of edges) {
11 const hasNodes = src in graph && dst in graph;
12 if (hasNodes && hasRedundantConnection(graph, src, dst))
13 return [src, dst];
14
15 graph[src].push(dst);
16 graph[dst].push(src);
17 }
18};
19
20const hasRedundantConnection = (graph, source, target, seen = new Set()) => {
21 if (seen.has(source)) return false;

Callers

nothing calls this directly

Calls 2

hasRedundantConnectionFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected