61. You must find the most frequent error codes in a log file larger than memory. How would you approach it?
MediumData structures & algorithms
Technical
Show model answer
Clarify whether exact counts are required and how many distinct codes may exist. Stream the file and update a frequency map if the distinct set fits in memory; the file size alone does not make that map too large.
If the distinct set is unbounded, partition or externally sort the data, or agree on an approximate streaming method with explicit error bounds. State input-reading and storage costs, handle malformed lines, and compare results against a small trusted fixture.
What interviewers listen for
- Separate input size from distinct count
- Bounded-memory strategy
- Exactness and cost tradeoffs