Find Largest Strongly Connected Component in Undirected Graph
1) Create a graph by having an node for each unique num and adding an edge between nodes where their value differs by 1\n2) Find the strongly connected componen
1) Create a graph by having an node for each unique num and adding an edge between nodes where their value differs by 1\n2) Find the strongly connected components in the graph. Since this is an undirected graph that can be done by a simple DFS. In a directed graph it would be more complicated.\n3) Return the length of the largest SCC in the graph\n\nTime and space complexity O(|V| + |E|) which is O(n^2)\n\n```\nclass Solution:\n    def longestConsecutive(self, nums: List[int]) -> int:\n        graph = self.constructGraph(nums)\n        components = self.getStronglyConnectedComponents(graph)\n        return max(len(c) for c in components) if len(components) > 0 else 0\n    \n    def constructGraph(self, nums):\n        nums = set(nums)\n        graph = {}\n        for num in nums:\n            graph[num] = []\n            if num-1 in nums:\n                graph[num].append(num-1)\n            if num+1 in nums:\n                graph[num].append(num+1)\n        return graph\n    \n    def getStronglyConnectedComponents(self, graph):\n        visited = set()\n        components = []\n        for node in graph:\n            if node in visited:\n                continue\n            currentComponent = []\n            self.explore(node, graph, visited, currentComponent)\n            components.append(currentComponent)\n        return components\n            \n    def explore(self, node, graph, visited, currentComponent):\n        currentComponent.append(node)\n        visited.add(node)\n        for neighbor in graph[node]:\n            if neighbor in visited:\n                continue\n            self.explore(neighbor, graph, visited, currentComponent)\n        return\n```
[]