Daily iOS
CS fundamentals and algorithms

Deduplicating beyond memory

You have a 1TB log file with one URL per line and need to remove duplicate URLs, but you only have 1GB of memory. How do you do it?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Partition the file by URL hash into chunks that fit in memory (say 2000), so identical URLs always land in the same chunk, then deduplicate each chunk with an in-memory Set and merge. If approximation is acceptable a Bloom filter does it in one pass, and external sort followed by adjacent comparison also works.

Share a question