Razorpay Recover Corrupted BST
Razorpay Recover Corrupted BST
HardTrees33% accepted
Razorpay transaction ledger is stored in a BST. A database bug swapped exactly two node values, corrupting the BST. Given the root of the corrupted BST, recover the tree by swapping back the two nodes in O(1) extra space (without changing tree structure).
Approach
Recover a BST where exactly two nodes were swapped, in O(1) extra space.
Input
3
1 3 -1 -1 2
Output
[3,1,null,null,2]
More Trees problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards