Fewest Distinct Hashtags to Remove to Halve a Post Set
Last updated: November 29, 2026
Quick Overview
Each post has one primary hashtag. Removing a hashtag removes every post that uses it. Return the fewest hashtags to remove so at least half the posts are gone.
Meta
November 29, 20260
0
0 solved
Each post has one primary hashtag. Removing a hashtag removes every post that uses it. Return the fewest hashtags to remove so at least half the posts are gone.
A Meta phone-screen question framed around trimming a content sample for a classifier. Interviewers want the greedy of removing the most frequent tags first and a crisp argument why it is optimal.
What the Interviewer Expects
- Count frequency per hashtag
- Remove tags in descending frequency order
- Stop as soon as removed posts reach half
- Mention bucket sort for O(n)
- Explain why greedy is optimal
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
- Do it in O(n) without sorting.
- What if each post can carry multiple hashtags?
- What if each hashtag has a removal cost?
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: list of hashtag IDs, one per post.
- Output: minimum number of distinct hashtags whose removal deletes at least
ceil(n / 2)posts. - Return 0 for an empty list....
High-Level Design
Removing k tags deletes the sum of their frequencies. For a fixed k, that sum is largest when we pick the k most frequent tags. So the answer is the smallest k for which the top k frequencies sum to a...