Typescript | Javascript | DFS | With comments
\n// This question can be rephrased as:\n// How many connected graphs we have\nfunction findCircleNum(isConnected: number[][]): number {\n  let numberOfProvince
```\n// This question can be rephrased as:\n// How many connected graphs we have\nfunction findCircleNum(isConnected: number[][]): number {\n  let numberOfProvinces = 0;\n  const visited = new Set<number>();\n  for(let i = 0 ; i < isConnected.length ; i++){\n    \n    // if I find a node that I haven\'t visited before (new graph)\n    // then visit all its neighbors (flood fill)\n    if(!visited.has(i)){\n      numberOfProvinces++;\n      dfs(i, isConnected, visited);\n    }\n  }\n  \n  return numberOfProvinces;\n};\n\nfunction dfs(city: number, graph: number[][], visited: Set<number>){\n  visited.add(city);\n  for(let neighbor = 0 ; neighbor < graph[city].length ; neighbor++){\n    if(graph[city][neighbor] === 1 && !visited.has(neighbor))\n      dfs(neighbor, graph, visited);\n  }\n}\n```
['Depth-First Search', 'TypeScript', 'JavaScript']