Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1083 |

@bt8816103042 | 739 |

@SherlockHolmes3 | 444 |

@SHOAIBVIJAPURE | 430 |

@codeantik | 429 |

@shalinibhataniya1097 | 400 |

@ShamaKhan1 | 392 |

@neverevergiveup | 372 |

@amrutakashikar2 | 355 |

@murarry3625 | 350 |

@mahlawatep | 349 |

Complete Leaderboard |

Given the adjacency list of a bidirectional graph. Your task is to return the adjacency list for each vertex.

**Example 1:**

**Input:**
**Output:**
0-> 1-> 4
1-> 0-> 2-> 3-> 4
2-> 1-> 3
3-> 1-> 2-> 4
4-> 0-> 1-> 3
**Explanation**:
As 0,1 and 3 is connected to 4 so 4th row
of the list containing 4 and its connected
nodes 0,1 and 3 and we have to add those in
sorted order and same for every row.

**Example 2:**

**Input:**
**Output:**
0-> 2-> 3
1-> 2
2-> 0-> 1
3-> 0
**Explanation**:
As 2 and 3 is connected to 0 so 0th row
of the list containing 0 and its connected
nodes 2 and 3 and we have to add those in
sorted order and same for every row.

**Your task:**

You don’t need to read input or print anything. Your task is to complete the function **printGraph()** which takes the integer V denoting the number of vertices and adjacency list as input parameters and returns the list of list contains the node itself with its connected nodes(as same as it is given in input adjacency list).

**Expected Time Complexity: **O(V + E)

**Expected Auxiliary Space: **O(1)

**Constraints:**

1 ≤ V, E ≤ 10^{4}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Print adjacency list

...