Find frequent IPs from a huge file
AsanaSoftware Engineer · OnsiteLast updated
This question evaluates a candidate's competency in large-scale data processing and algorithm design, focusing on memory- and disk-constrained frequency estimation, streaming and approximation concepts.
You are given a very large log file (too large to fit in memory). Each line contains an IPv4 address (e.g., 203.0.113.7).
Design an approach to answer one of these variants under memory constraints:
- Variant A: Find the single most frequent IP.
- Variant B: Find the top
Kmost frequent IPs.
Explain how you would implement it in practice (data structures, disk usage, complexity), and how your approach changes if:
- Memory is limited to, say, 256MB.
- The file is tens/hundreds of GB.
- You only need an approximate answer.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.