Recover Binary Search Tree
Two nodes of a BST are swapped by mistake. Recover the tree without changing its structure.
Recover Binary Search Tree

Two nodes of a BST are swapped by mistake. Recover the tree without changing its structure.

Example 1:
Input: {"root":[1,3,null,null,2]}
Output: [3,1,null,null,2]
Input
arr ={"root":[1,3,null,null,2]}

Initialize first, second, prev to null. Start in-order traversal.

Phase

traversing

1

3

2

Current Node
Previous Node
Swapped Nodes
Visited
Variables
No variables to display
DepthFunction Call
Stack empty
0/23