Simple UnderStanding
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nDFS AND FIND MAX\n\n# Complexity\n- Time complexity:\n Add your time comp
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nDFS AND FIND MAX\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int[] maxTargetNodes(int[][] edges1, int[][] edges2, int k) {\n       \n         int []arr1 = helper(edges1,k);\n         System.out.println();\n         int []arr2 = helper(edges2,k-1);\n         int max = 0;\n         for(int i=0;i<arr2.length;i++) max = Math.max(arr2[i],max);\n         for(int i=0;i<arr1.length;i++) arr1[i] += max;\n        return arr1;\n         \n\n    }\n\n    public int[] helper(int[][] edges1,int k){\n         HashMap<Integer,ArrayList<Integer>> map = new HashMap<>();\n\n        for(int []ch:edges1){\n            int start = ch[0];\n            int end = ch[1];\n\n            map.computeIfAbsent(start,key -> new ArrayList<>());    \n            map.computeIfAbsent(end,key -> new ArrayList<>()); \n\n            map.get(start).add(end);\n            map.get(end).add(start);\n         }\n        int []arr1 = new int[edges1.length+1];\n        \n         \n         for(int i=0;i<=edges1.length;i++){\n            HashSet<Integer> v = new HashSet<>();\n            dfs(map,i,v,0,k);\n            arr1[i] = v.size();\n            System.out.print(arr1[i] + " ");\n         }\n\n         return arr1;\n    }\n    public void dfs(HashMap<Integer,ArrayList<Integer>> map,int index,HashSet<Integer> visited,int count,int k){\n        if(k < 0) return;\n          visited.add(index); \n          if(count == k) return;\n          for(int node : map.get(index)){\n            if(!visited.contains(node)){\n                dfs(map,node,visited,count+1,k);\n            }\n          }\n    }\n}\n```
['Java']