Given a Binary Search Tree (BST) that may contain duplicate values, remove all duplicate nodes so that every value appears only once in the tree. The resulting tree should remain a valid BST.
Input: [1,2,2,3,4,4,4,5](BST with inorder traversal:12234445)Output: [1,2,3,4,5](BST with inorder traversal:12345)Explanation: All duplicate nodes are removed, only unique values remain.
Duplicates in a BST appear as consecutive nodes in an inorder traversal. By tracking the previous node, we can detect and remove duplicates efficiently.
Traverse the BST in-order. If the current node’s value equals the previous node’s value, remove the current node and continue. Otherwise, update the previous node and proceed.