Search
⌘K

Leetcode 99. Recover Binary Search Tree

Given a BST where exactly two nodes' values were swapped, restore the tree in-place (without changing its structure) so it satisfies the BST property. The core challenge is detecting the two nodes by identifying out-of-order elements in an inorder traversal (straightforward with O(n) space or achievable in O(1) space using Morris traversal) and swapping their values.

Asked at:

Microsoft

Microsoft


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Mid January, 2026

Microsoft

Microsoft

Senior

Comments

Your account is free and you can post anonymously if you choose.