Your question is Top K IPs Log Parsing. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Dell PowerStore telemetry can produce log streams too large to load into memory at once. Given an iterable of log lines, return the k most frequent IP addresses while counting each line in a single pass.
Each non-empty log line begins with an IP address, followed by zero or more fields separated by whitespace. Every IP address is valid. If multiple addresses have the same frequency, order them lexicographically by IP address. Return results ordered by decreasing frequency, then lexicographic IP order.
Implement top_k_ips(log_lines, k).
log_lines, an iterable of strings, and k, a positive integer.k strings containing the most frequent IP addresses.k is greater than the number of distinct IP addresses, return every distinct address.def top_k_ips(log_lines, k):