Find Reactions Chosen by More Than a Third of Viewers

Last updated: November 29, 2026

Quick Overview

Given the list of reaction types left on a live video, return every reaction type that appears more than n/3 times, using linear time and constant extra space.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given the list of reaction types left on a live video, return every reaction type that appears more than n/3 times, using linear time and constant extra space.

An extension of majority vote that Meta interviewers like because the O(n) space answer is easy and the O(1) space answer needs a real idea. They check that you know at most two candidates can exceed n/3 and that you verify candidates with a second pass.

What the Interviewer Expects
  • Notes that a hash map solves it in O(n) space and asks if that is acceptable
  • Argues at most two values can exceed n/3
  • Runs extended Boyer-Moore voting with two candidates and two counters
  • Verifies candidates with a second counting pass
  • Handles inputs with fewer than two qualifying values
Key Topics to Cover
boyer-moore voting
hashing
heavy hitters
constant space
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
  • Generalize to values appearing more than n/k times. What is the space cost?
  • The reactions arrive as a stream too large to store; can you still answer approximately?
  • Why is the verification pass necessary? Give a counterexample without it.
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: reactions, a list of hashable values of length n. Output: the list of values with count strictly greater than n // 3, in any order (we return them sorted for testing). Target O(n) time and ...

High-Level Design

If three values each appeared more than n/3 times the total would exceed n, so there are at most two answers. Keep two candidate slots with counters. For each value: if it matches a candidate, increme...


Submit Your Answer
Markdown supported