Embercode
✕
Maps and SetsCoding problems

Maps and Sets: coding problems

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

0 of 8 solved

  • A small shop app records the id of every visitor who opens its page today. The same visitor can open the page many times, so ids repeat.

    Count how many different visitors came in. Use a HashSet: add returns false for an id you have already seen.

    **Constraints:** n is between 1 and 30000. Each id is an integer between -1000000000 and 1000000000.

    Input. The first line holds n. The second line holds n integers separated by spaces.

    Output. One integer: the number of distinct ids.

    Example 1 input

    5
    4 9 4 1 9
    

    Output

    3
    

    Example 2 input

    3
    -1000000000 1000000000 -1000000000
    

    Output

    2