✔️ PYTHON || EXPLAINED || ;]
UPVOTE IF HELPFuuL\n\nObservation : \nscore = number of above nodes * number of nodes of 1 child * number of nodes ofother child\n\nWe are provided with the par
**UPVOTE IF HELPFuuL**\n\n**Observation** : \nscore = ```number of above nodes * number of nodes of 1 child * number of nodes ofother child```\n\nWe are provided with the parents of nodes, For convenience we keep mapping of chilren of nodes.\n\n* First task : Create a dictionary to keep the children of nodes.\n* Secondly, with recurssion we find number of nodes below and including itself for ```node i``` and store in ```nums```\n\nNow use formula :\n* Number of nodes above node i = Total nodes - ```nums[i]``` . -> nums [ i ] is number of nodes below it + 1.\n* Number of nodes for children are provided directly stored in nums dictionary.\n\n**UPVOTE IF HELPFuuL**\n\n```\nclass Solution:\n    def countHighestScoreNodes(self, parents: List[int]) -> int:\n        \n        def fin(n):\n            k=1\n            for i in child[n]:\n                k += fin(i)\n            nums[n]=k\n            return k\n        \n        child = {}\n        for i in range(len(parents)):\n            child[i]=[]\n        for i in range(1,len(parents)):\n            child[parents[i]].append(i)\n        \n        nums={}\n        fin(0)\n        k=1\n        for i in child[0]:\n            k*=nums[i]\n        score=[k]\n        for i in range(1,len(nums)):\n            k=1\n            k*=(nums[0]-nums[i])\n            for j in child[i]:\n                k*=nums[j]\n            score.append(k)\n            \n        return score.count(max(score))\n```\n![Uploading file...]()\n
['Python3']