Repeatedly Collide the Two Largest Spam Scores Until One Remains

Last updated: November 29, 2026

Quick Overview

Each round, take the two largest spam scores x >= y. If they are equal both are removed; otherwise they are replaced by x - y. Return the last remaining score, or 0 if none remain.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Each round, take the two largest spam scores x >= y. If they are equal both are removed; otherwise they are replaced by x - y. Return the last remaining score, or 0 if none remain.

A short Meta online-assessment style heap exercise with an integrity flavor. It checks that you can simulate with a max-heap in Python (which only has a min-heap) without off-by-one mistakes.

What the Interviewer Expects
  • Use a max-heap by negating values
  • Pop two, push the difference if non-zero
  • Return 0 when the heap empties
  • State O(n log n)
  • Write it in a few clean lines
Key Topics to Cover
max-heap
simulation
heapq negation
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
  • Return the minimum possible remaining value if you may pick any two each round.
  • What if values are bounded by 100: can you do it in O(n + range)?
  • What if scores are floats with a tolerance for equality?
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 non-negative integer scores.
  • Each round picks the two largest.
  • Output: the final score, or 0 if all are removed....
High-Level Design

We repeatedly need the largest two items and insert a new one, so a max-heap fits. Python's heapq is a min-heap, so store negated values.

Loop while at least two items remain: pop two, and if t...


Submit Your Answer
Markdown supported