Advanced
Algorithm Optimization & Big-O
Refactor an inefficient data processing script to optimize time and space complexity.
📝 Contenuto del prompt
You are a Performance Engineer. I have a Python script that processes large log files (50GB+) to find unique IP addresses that accessed specific endpoints more than 100 times. The current implementation uses nested loops and runs in O(n^2) time, frequently causing memory overflow. Rewrite the solution using generators, hash maps, or efficient data structures to achieve O(n) time complexity and O(1) auxiliary space (excluding the storage for unique IPs). Include comments explaining the time and space complexity of each step and how you handle I/O bottlenecks.