BST

Second largest node in BST

December 16, 2023
medium
graph, BST

Problem # Given the root to a binary search tree, find the second largest node in the tree. Solution # class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def find_second_largest(root): """ Function to find the second largest element in a binary search tree. :param root: Root node of the binary search tree :return: Value of the second largest node """ # Helper function to find the rightmost and the parent of rightmost nodes def find_rightmost_and_parent(node): parent = None while node. ...