Find a pair in BST whose sum is equal to a given sum - PrismoSkills
One solution can be to write the BST into an array during inorder traversal.
Then use the above solution.
The auxiliary array can be avoided if we can somehow traverse the tree in inorder from right and left ends simultaneously.
Normal inorder traversal LDR gives left-to-right traversal in the corresponding array.
And reverse inorder traversal RDL gives right-to-left traversal in the array.
Read full article from Find a pair in BST whose sum is equal to a given sum - PrismoSkills
One solution can be to write the BST into an array during inorder traversal.
Then use the above solution.
The auxiliary array can be avoided if we can somehow traverse the tree in inorder from right and left ends simultaneously.
Normal inorder traversal LDR gives left-to-right traversal in the corresponding array.
And reverse inorder traversal RDL gives right-to-left traversal in the array.
Read full article from Find a pair in BST whose sum is equal to a given sum - PrismoSkills