Challenge: Print the Transpose of a Graph

Given a graph, find its transpose.

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 the Graph.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.


The input is a graph.


The output is the transpose of the graph.

Sample input

graph = {
    0 -> 2
    0 -> 1
    1 -> 4
    1 -> 3}

Sample output


Level up your interview prep. Join Educative to access 70+ hands-on prep courses.