Given an array of log lines logs, where each line is a string, write a function that extracts error codes and returns the 10 most frequent codes. An error code is any token that starts with ERROR_ and is followed by uppercase letters, digits, or underscores. Return a list of (code, count) pairs sorted by descending frequency, and break ties by lexicographically smaller code first.
Example 1:
Input: logs = [
"INFO start",
"ERROR_TIMEOUT request failed",
"WARN retry",
"ERROR_TIMEOUT again",
"ERROR_AUTH invalid token"
]
Output: [("ERROR_TIMEOUT", 2), ("ERROR_AUTH", 1)]
Explanation: ERROR_TIMEOUT appears twice and ERROR_AUTH appears once.
Example 2:
Input: logs = [
"ERROR_Z",
"ERROR_A",
"ERROR_Z",
"ERROR_A"
]
Output: [("ERROR_A", 2), ("ERROR_Z", 2)]
Explanation: Counts tie, so codes are ordered lexicographically.
1 <= len(logs) <= 10^50 <= len(logs[i]) <= 10^3Given an array of log lines logs, where each line is a string, write a function that extracts error codes and returns the 10 most frequent codes. An error code is any token that starts with ERROR_ and is followed by uppercase letters, digits, or underscores. Return a list of (code, count) pairs sorted by descending frequency, and break ties by lexicographically smaller code first.
Example 1:
Input: logs = [
"INFO start",
"ERROR_TIMEOUT request failed",
"WARN retry",
"ERROR_TIMEOUT again",
"ERROR_AUTH invalid token"
]
Output: [("ERROR_TIMEOUT", 2), ("ERROR_AUTH", 1)]
Explanation: ERROR_TIMEOUT appears twice and ERROR_AUTH appears once.
Example 2:
Input: logs = [
"ERROR_Z",
"ERROR_A",
"ERROR_Z",
"ERROR_A"
]
Output: [("ERROR_A", 2), ("ERROR_Z", 2)]
Explanation: Counts tie, so codes are ordered lexicographically.
1 <= len(logs) <= 10^50 <= len(logs[i]) <= 10^3