Premium

Recover a BST with Two Swapped Nodes

By FrontendAtlas Editorial · Updated Jan 30, 2026

Challenge summary

Restore ordering in a binary search tree when exactly two node values have been exchanged.

What you'll practice

  • Use in-order traversal to identify ordering inversions.
  • Handle both adjacent and separated swapped nodes.
  • Repair values in place while preserving the original tree structure.

What Premium unlocks

Premium unlocks the runnable workspace, behavioral checks, implementation walkthrough, and edge-case discussion.

Free related practice

Upgrade to FrontendAtlas Premium to unlock this challenge. Already upgraded? Sign in to continue.