Java Clean Solution | Daily Challenge
Code\n\nclass Solution {\n\n    private List<Integer> helperSort(int[][] arr, int k) {\n        int[] deg = new int[k];\n        List<List<Integer>> list = new 
# Code\n```\nclass Solution {\n\n    private List<Integer> helperSort(int[][] arr, int k) {\n        int[] deg = new int[k];\n        List<List<Integer>> list = new ArrayList<>();\n        for (int i = 0; i < k; i++) {\n            list.add(new ArrayList<>());\n        }\n\n        Queue<Integer> q = new LinkedList<>();\n        for (int[] a : arr) {\n            list.get(a[0] - 1).add(a[1] - 1);\n            deg[a[1] - 1]++;\n        }\n\n        for (int i = 0; i < k; i++) {\n            if (deg[i] == 0) {\n                q.add(i);\n            }\n        }\n\n        List<Integer> res = new ArrayList<>();\n        while (!q.isEmpty()) {\n            int temp = q.poll();\n            res.add(temp + 1);\n            for (int l : list.get(temp)) {\n                if (--deg[l] == 0) {\n                    q.add(l);\n                }\n            }\n        }\n        return res;\n    }\n\n    public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {\n        List<Integer> list1 = helperSort(rowConditions, k);\n        List<Integer> list2 = helperSort(colConditions, k);\n\n        if (list1.size() < k || list2.size() < k) {\n            return new int[0][0];\n        }\n\n        Map<Integer, Integer> map = new HashMap<>();\n        for (int i = 0; i < k; i++) {\n            map.put(list2.get(i), i);\n        }\n\n        int[][] res = new int[k][k];\n        for (int i = 0; i < k; i++) {\n            res[i][map.get(list1.get(i))] = list1.get(i);\n        }\n        return res;\n    }\n}\n```
['Array', 'Graph', 'Topological Sort', 'Matrix', 'Java']