Challenge: Print the Transpose of a Graph
Given a graph, find its transpose.
We'll cover the following
Problem statement
You have to implement a function that takes a directed graph as input and print its transpose.
Important note: The
printGraph()
function is given in theGraph.Java
file; you can check out its implementation there. The function has already been called in the code as well. All you have to do is write your implementation for getting the transpose of the graph.
Input
The input is a graph.
Output
The output is the transpose of the graph.
Sample input
graph = {
0 -> 2
0 -> 1
1 -> 4
1 -> 3}
Sample output
4-->1
3-->1
1-->0
2-->0
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.