391. Build a BST by Insertion
EasyBST
Insert the values into an empty BST in the given order (ignore duplicates). Print the preorder traversal of the result.
Input format
Line 1: n Line 2: n values
Output format
The preorder traversal.
Example 1
Input
7 50 30 70 20 40 60 80
Output
50 30 20 40 70 60 80
Example 2
Input
3 1 2 3
Output
1 2 3
Constraints
1 ≤ n ≤ 5000
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…