Remove the Fewest Error Codes to Halve a Crash Report Log

Last updated: November 29, 2026

Quick Overview

An Android crash log is a list of error codes, one per line. Pick the smallest set of distinct codes such that deleting every line with those codes removes at least half the lines, and return the size of that set.

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

0

0

0 solved


An Android crash log is a list of error codes, one per line. Pick the smallest set of distinct codes such that deleting every line with those codes removes at least half the lines, and return the size of that set.

A frequency greedy that suits a Google online assessment and the Android vitals context of triaging the most common crashes first. The interviewer checks that you remove the most frequent codes first and stop at the halfway mark.

What the Interviewer Expects
  • Count lines per error code
  • Sort counts descending
  • Remove codes until at least half the lines are gone
  • Explain why most-frequent-first is optimal
  • O(n log n) or O(n) with bucket sort
Key Topics to Cover
Greedy
Hash map 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
  • Remove at least a fraction f of lines instead of half.
  • Codes have a cost to fix; minimize total cost.
  • Return which codes to remove.
  • Do it in O(n) using bucket sort.
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 codes (ints or strings). Output: minimum number of distinct codes whose combined counts are at least ceil(n / 2)....

High-Level Design

Each removed code contributes its count. To reach a threshold with the fewest codes, always take the largest remaining count: any set of size k removes at most the sum of the k largest counts, so if g...


Submit Your Answer
Markdown supported