[JAVA] Easy + Clear Explanation + Clean Code O(N)
As shown in the image Below :\nwe Just need to find the No of Nodes in Left Sub-Tree , Right SubTree and the parent SubTree \nand multiply them to find the prod
As shown in the image Below :\nwe Just need to find the No of Nodes in Left Sub-Tree , Right SubTree and the parent SubTree \nand multiply them to find the product generated if we remove the current Node \n**Steps** :\n1. DFS to  find the No of Nodes in each subTree \n2. no for i in Range 0 to N-1 cal the Above Product \n3. then Find the max among all the product and count No of times max occours;\n\nBelow is Code :\nSimple and Concise :\n```\nList<Integer>[] adj;\n    int N;\n     public int countHighestScoreNodes(int[] par) {\n         N=par.length;\n         adj=new List[N];\n         for(int i=0;i<adj.length;i++)adj[i]=new Vector<Integer>();\n\n         for(int i=0;i<par.length;i++) {//build Tree\n             if(par[i]==-1) continue;\n             adj[par[i]].add(i);\n         }\n\n         long mx=Long.MIN_VALUE;\n         dp=new Integer[N];//arr for storing noOfNodes\n         noOfNodes(0);\n\n         List<Long> list=new Vector<>();\n         for(int i=0;i<par.length;i++) {\n            long product=1;\n             int left=(adj[i].size()>=1)?dp[adj[i].get(0)]:1; //if left child exist then cal. else left=1\n             int right=(adj[i].size()>=2)?dp[adj[i].get(1)]:1;\n             if(par[i]==-1)\n                 product=product*left*right;\n             else \n                 product=product*left*right*(dp[0]-dp[i]);\n\n             mx=Math.max(mx, product);\n             list.add(product);\n         }\n         int cnt=0;\n        for(long x:list)\n            if(x==mx)cnt++;\n\n        return cnt;\n     }\t\t\n\n     Integer[] dp;\n     int noOfNodes(int i) {\n        if(dp[i]!=null) return dp[i]; \n\n         int no=1;\n         for(int child:adj[i]) {\n             no+=noOfNodes(child);\n         }\n         return dp[i]=no;\n     }\n```\nTime Complexity - O(N)\n**Please Upvote if you found Useful !!**\n\n\n\n![image](https://assets.leetcode.com/users/images/9de9bdd7-19ab-4aab-9d7d-10be2074ef90_1635085528.169347.png)\n\n
['Dynamic Programming', 'Tree', 'Depth-First Search', 'Java']