Find the First Hashtag Used Exactly Once in a Post
Last updated: November 29, 2026
Quick Overview
Given a list of hashtags in the order they appear in a post or thread, return the first hashtag that occurs exactly once, or None if every hashtag repeats.
Meta
November 29, 20260
0
0 solved
Given a list of hashtags in the order they appear in a post or thread, return the first hashtag that occurs exactly once, or None if every hashtag repeats.
Meta data engineering screens include a Python coding portion with short hashing tasks like this. The interviewer checks that you count first and then scan in original order, and that you can extend the idea to a stream.
What the Interviewer Expects
- Counts occurrences with a dictionary or Counter in one pass
- Makes a second pass in original order to find the first count of one
- Normalizes case if the product treats #Meta and #meta as the same tag
- Gives O(n) time and O(u) space
- Discusses how the answer changes when tags arrive as a stream
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Tags now arrive one at a time; return the first unique tag after each arrival.
- How would you compute this per post for a billion posts in a batch pipeline?
- Return the k earliest unique tags instead of one.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: tags, a list of strings. Output: the earliest tag whose total count is 1, else None. Ask whether matching is case-insensitive; here we normalize to lowercase and return the tag as it first ...
High-Level Design
Two passes. First pass builds count[tag.lower()]. Second pass walks tags in order and returns the first one whose normalized count is 1. Order matters, so a plain set of uniques is not enough. For...