Unique Visitors

Easy · rating 950 · hashing, strings

A web server logged visitor IDs for the day. The first line contains n. The second line contains n space-separated IDs. Print how many distinct visitors there were.

Editorial

Unique Visitors counts the distinct IDs in a day's log — a direct use of a hash set, whose size after inserting every ID is the answer.

print(len(set(ids)))

Complexity

Time: O(n). Space: O(n).

Open Unique Visitors in Code Arena →