As reported: Rivian Senior Software Engineer loop (California, 2025), first coding round: convert a binary search tree into a min heap (with SQL queries in the same round).
You are given the root of a binary search tree with distinct values that is a complete binary tree. Convert it into a min heap in place, keeping the tree's shape and only rewriting values, so that:
- every node's value is smaller than the values of its children (min-heap property), and
- for every node, all values in its left subtree are smaller than all values in its right subtree.
Together these mean the tree's preorder traversal lists the values in increasing order, which makes the answer unique.
Example 1
Input: [4,2,6,1,3,5,7] Output: [1,2,5,3,4,6,7]
4 1
/ \ / \
2 6 -> 2 5
/ \ / \ / \ / \
1 3 5 7 3 4 6 7
Example 2
Input: [8,4,12,2,6,10,14] Output: [2,4,10,6,8,12,14]
Constraints: 1 ≤ number of nodes ≤ 3·10^4; values are distinct, in [−10^6, 10^6]; the tree is a complete BST.
Code runner format: the tree as a level-order JSON array; implement convertToMinHeap(root), which modifies the tree in place. The runner prints the tree in level order.