count-nodes-with-the-highest-score C# Solution
\n\n# Code\ncsharp []\npublic class Solution {\n    Dictionary<int, int[]> parentDict = new();\n    int result = 0;\n    long maxScore = 0;\n    \n    public in
\n\n# Code\n```csharp []\npublic class Solution {\n    Dictionary<int, int[]> parentDict = new();\n    int result = 0;\n    long maxScore = 0;\n    \n    public int CountHighestScoreNodes(int[] parents) {\n        for(int i=0; i< parents.Length; i++){\n            parentDict.TryAdd(i, new int[2]);\n        }\n        for(int i=1; i<parents.Length; i++){\n            if(parentDict[parents[i]][0] == 0) parentDict[parents[i]][0] = i;\n            else parentDict[parents[i]][1] = i;\n        }\n\n        CountScores(0, parents.Length);\n        return result;\n    }\n\n    public int CountScores(int index, int totalSize){\n        int left = 0, right = 0;\n        long count =1;\n        if(parentDict[index][0] != 0) left = CountScores(parentDict[index][0], totalSize);\n        if(parentDict[index][1] != 0) right = CountScores(parentDict[index][1], totalSize);\n\n        int subTree = left + right +1;\n        int other = totalSize - subTree;\n        if(left != 0) count *= (long)left;\n        if(right != 0) count *= (long)right;\n        if(other != 0) count *= (long)other;\n        if(count == maxScore) result++;\n        else if(count > maxScore){\n            maxScore = count;\n            result = 1;\n        } \n        return subTree;\n\n    }\n}\n```
['Array', 'Tree', 'Depth-First Search', 'Binary Tree', 'C#']