Maximum Winning Score Geeks For Geeks
Problem Link:
https://practice.geeksforgeeks.org/problems/4ead9c3991a3822f578309e2232bc5415ac35cb9/1#
It is also the problem of the day for 5 march.
Solution:
class Solution
{
public static Long findMaxScore(Node root)
{
Node temp=root;
long sum=0;
while(temp!=null){
if(temp.right==null && temp.left==null){
return (long) temp.data;
}
else{
return (long) temp.data*Long.max(findMaxScore(temp.left),findMaxScore(temp.right));
}
}
return sum;
}
}
Time Complexity:[GFG Time:0.7/2.9]
Space Complexity: O(N)[Number of nodes given in tree]
Auxiliary Space: O(1)
Approach Used:
Here we used an approach that we will traverse recursively.
And when we travel recursive we follow the bottom to the top approach of the tree.
It means we will see the leaf node and then move up to the tree.
For recursion, we should have a base condition and that is when node. right or node. left are null. It means leaf nodes and
Total Test Cases:211
Comments
Post a Comment