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).
Related problems
- Distinct Words — Easy
- Most Common Word — Medium
- First Unique Character — Medium
- Election Winner — Medium
- Keypad Taps — Medium
- Count Anagram Groups — Medium