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
November 29, 20260
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
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
- 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 ProblemsSample 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...