shecoderfinally / Sorting-and-Searching-Techniques

Make your Contributions for Hacktoberfest keeping the guidelines in mind.
21 stars 111 forks source link

Maximum Sum BST in Binary Tree #257

Open krishan821 opened 2 years ago

krishan821 commented 2 years ago

Given a binary tree root, return the maximum sum of all keys of any sub-tree which is also a Binary Search Tree (BST).

Assume a BST is defined as follows:

The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search trees.

I have solved this problem in java