Loading...
Loading...
Loading...
Insert a key into a binary search tree. If the key is already in the tree, change nothing. Print the keys of the final tree in preorder (node, left subtree, right subtree), separated by spaces.
Example 1
Input
8 3 10 6
Output
8 3 6 10
Example 2
Input
8 3 10 10
Output
8 3 10
10 is already there.
Try the problem first. Open one hint at a time.
Follow the search path until a child is missing, then attach the new node there.
Do nothing when the key equals a node's key.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor