class Solution { public ArrayList topoSort(int V, int[][] edges) { ArrayList res = new ArrayList<>(); ArrayList> adj = new ArrayList<>(); for(int i=0; i()); } for(int[] edge : edges) { int u = edge[0]; int v = edge[1]; adj.get(u).add(v); } // Step-1 Create an indegree array int[] indegree = new int[V]; for(int i=0; i q = new LinkedList<>(); for(int i=0; i