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
Coding & Algorithms
Data Engineer
Meta
November 29, 2026
Data Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
greedy
frequency counting
sorting
bucket sort
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported