Minimum and Maximum of a Binary Tree
Technique: FAITH technique of Recursion
Problem Link: https://practice.geeksforgeeks.org/problems/max-and-min-element-in-binary-tree/1/
global maxx
global minn
class Solution:
def findMax(self,root):
#code here
global maxx
if(root is None):
return -999999999999
lmax=self.findMax(root.left)
rmax=self.findMax(root.right)
ans=max(lmax,rmax)
return max(ans,root.data)
def findMin(self,root):
#code here
global minn
if(root is None):
return 999999999999
lmin=self.findMin(root.left)
rmin=self.findMin(root.right)
ans=min(lmin,rmin)
return min(ans,root.data)
Last updated