Code Room
CodingHardcod-g303
Subject Binary search treeLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Exactly two nodes of a binary search tree have had their values swapped by mistake (the tree shape is unchanged). Given the tree as a level-order list (None marks a missing child; children of None are omitted), recover the BST by swapping those two values back, then return the corrected inorder traversal as a list of values. All values are distinct. An empty tree returns [].

Implement
recover_bst(level: list) → list[int]
Examples
in[[1,3,null,null,2]]out[1,2,3]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.