Your question is Finding Frequent Error Patterns. 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.
Oracle Health services produce logs containing timestamps, severity levels, error codes, and messages. Given an array of log strings, identify the k most frequent error patterns while grouping messages that differ only by numeric values.
Each log has the format timestamp level error_code message, where the message may contain spaces. Consider only logs whose level is ERROR. A pattern consists of the error code followed by the message after replacing every standalone sequence of decimal digits with <NUM>.
Return a list of [pattern, count] pairs ordered by decreasing frequency. If two patterns have the same frequency, order them lexicographically by their pattern string.
logs, a list of valid strings, and k, a positive integer.k pairs. Each pair contains a normalized pattern string and its occurrence count.def identify_error_patterns(logs, k):