BackmediumGraphs graphs medium

Graph Connectivity Checker Solution

Problem Statement

You are given a graph represented as an adjacency list, where each key is a node and its corresponding value is a list of neighboring nodes. Implement a function to check if all nodes in the graph are connected and return 'Connected' if they are, otherwise return 'Not Connected'. The input graph is represented as a dictionary where each key is a node and its corresponding value is a list of neighboring nodes.

Example 1
Input
{"0: [1, 2], "1: [0, 2], "2: [0, 1]}
Output
Connected

Explanation: The graph has three nodes and they are all connected to each other.

Constraints

  • 1 <= number of nodes <= 1000
  • 0 <= number of edges <= 10000
  • The input graph is a dictionary where each key is a node and its corresponding value is a list of neighboring nodes
  • The function should return 'Connected' if all nodes are connected, otherwise return 'Not Connected'
  • The function should have a time complexity of O(V + E), where V is the number of nodes and E is the number of edges
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free