Find the Value Most Replicas Agree On With Constant Memory

Last updated: November 29, 2026

Quick Overview

A storage system reads the same key from n replicas and receives a list of values; one value is guaranteed to appear more than n/2 times. Return that value using O(1) extra memory.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


A storage system reads the same key from n replicas and receives a list of values; one value is guaranteed to appear more than n/2 times. Return that value using O(1) extra memory.

This shows up as a short Google technical screen question themed on quorum reads in a replicated store like Spanner or Bigtable. The hash-map count is accepted as a first step, but the interviewer is looking for the Boyer-Moore voting algorithm and a convincing argument for why it works.

What the Interviewer Expects
  • Offers the hash map counting solution first
  • Derives Boyer-Moore majority voting for O(1) space
  • Explains the cancellation argument for correctness
  • Adds a verification pass when majority is not guaranteed
  • Handles a single replica
Key Topics to Cover
Boyer-Moore Voting
Hash Map
Majority Element
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
  • What if a majority is not guaranteed and you must report None when none exists?
  • Find all values appearing more than n/3 times in O(1) space.
  • How would you combine votes computed on separate shards?
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: non-empty list values of hashable items.
  • Guarantee: some value appears more than len(values) // 2 times.
  • Output: that value.
  • Constraint: O(1) extra space, O(n) time....
High-Level Design

A Counter solves it in O(n) time and O(d) space. To reach O(1) space, use voting: keep a candidate and a count. When count is 0, adopt the current value as candidate. A matching value incremen...


Submit Your Answer
Markdown supported