public static void main(String args[]){
        Graph<Integer> graph = new Graph<Integer>(true);
        graph.addEdge(0, 3);
        graph.addEdge(0, 2);
        graph.addEdge(0, 4);
        graph.addEdge(3, 2);
        graph.addEdge(2, 0);
        graph.addEdge(4, 3);
        graph.addEdge(4, 1);
        graph.addEdge(1, 2);
        
        CloneDirectedGraph<Integer> cg = new CloneDirectedGraph<>();
        Graph<Integer> clonedGraph = cg.clone(graph);
        System.out.println(clonedGraph);
   }
Given a directed graph clone it in O(n) time where n is total number of edges
Test cases
Graph is directed/non directed
Graph has 0 edges
Graph has cycle
Graph is linear
Graph is dense
Graph is sparse
src/com/interview/graph/CloneDirectedGraph.java