Embercode
✕
Binary Search TreesCoding problems

Binary Search Trees: coding problems

Write a program that reads the input and prints the answer. Run checks it against every test, including hidden ones.

0 of 7 solved

  • A shop writes down the price of every item it sells during the day. Many prices repeat. The manager wants one sorted list of the different prices, with repeats removed.

    Store each price in a binary search tree. A price that is already in the tree is ignored. When every price is stored, print the tree's values in increasing order.

    Constraints: 1 <= n <= 2000, and each price is an integer from 1 to 1000000.

    Input. Line 1: `n`. Line 2: the `n` prices, in the order they were written down.

    Output. One line with the distinct prices in increasing order, separated by single spaces.

    Example 1 input

    5
    3 9 2 9 7
    

    Output

    2 3 7 9
    

    Example 2 input

    1
    42
    

    Output

    42