99. Recover Binary Search Tree
Description
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Constraints
Approach
Links
Examples
Input: [1, 3, null, null, 2]
Output: [3, 1, null, null, 2]
Input: [3, 1, 4, null, null, 2]

Output: [2, 1, 4, null, null, 3]

Solutions
Follow up
A solution using O(n) space is pretty straight forward.
Could you devise a constant space solution?
Last updated
Was this helpful?