Home
Topics
Practice
Roadmap
DSA Tracker
Code Editor
Tech Blogs
More
Sign in
Get started
Loading question...
Feedback
Recover Binary Search Tree
Hard
00:00
0 users online
Share
Description
Solution
Submissions
Discussion
Recover a BST where two nodes were swapped by mistake.
Sample Input:
[1,3,null,null,2]
Sample Output:
[3,1,null,null,2]
Hints
Hint 1
Use inorder traversal to find swapped nodes
Hint 2
Track previous node during traversal
Hint 3
Swap values of the two incorrect nodes
Code Editor
Reset
Run
Save
Loading...