an HCL GUVI product

21. Convert to Sum Tree

Required Input:

123

Expected Output:

Sum Tree converted

Code In Python

class TreeNode: def __init__(self, val): self.val = val self.left = None self.right = None def to_sum_tree(root): # Write your logic here pass

Run Code?

Click Run Button to view compiled output

22. Mirror Trees Check

Required Input:

123
132

Expected Output:

True

Code In Python

class TreeNode: def __init__(self, val): self.val = val self.left = None self.right = None def are_mirror(root1, root2): # Write your logic here pass

Run Code?

Click Run Button to view compiled output

23. Count Leaf Nodes

Required Input:

123

Expected Output:

2

Code In Python

class TreeNode: def __init__(self, val): self.val = val self.left = None self.right = None def count_leaves(root): # Write your logic here pass

Run Code?

Click Run Button to view compiled output

24. Path Sum Exists

Required Input:

548

Expected Output:

True

Code In Python

class TreeNode: def __init__(self, val): self.val = val self.left = None self.right = None def has_path_sum(root, target): # Write your logic here pass

Run Code?

Click Run Button to view compiled output

25. Maximum Depth of Binary Tree

Required Input:

123

Expected Output:

3

Code In Python

class TreeNode: def __init__(self, val): self.val = val self.left = None self.right = None def max_depth(root): # Write your logic here pass

Run Code?

Click Run Button to view compiled output

3 of 3