
Given an array of log lines logs and an array of target error codes target_codes, return a dictionary mapping each target error code to the number of times it appears in the logs. A valid error code appears in the form ERROR_CODE=<code> within a log line. Ignore malformed lines and codes not present in target_codes.
Example 1:
Input: logs = [
"ts=1 level=INFO msg=start",
"ts=2 level=ERROR ERROR_CODE=E101 msg=timeout",
"ts=3 level=ERROR ERROR_CODE=E101 msg=retry",
"ts=4 level=ERROR ERROR_CODE=E202 msg=failed"
], target_codes = ["E101", "E202", "E999"]
Output: {"E101": 2, "E202": 1, "E999": 0}
Explanation: E101 appears twice, E202 once, and E999 does not appear.
Example 2:
Input: logs = [
"ERROR_CODE=E500",
"level=WARN msg=skip",
"ERROR_CODE=E404 extra=data",
"ERROR_CODE=E500"
], target_codes = ["E404", "E500"]
Output: {"E404": 1, "E500": 2}
Explanation: Only exact target codes are counted.
1 <= len(logs) <= 10^51 <= len(target_codes) <= 10^41 and 10^3Given an array of log lines logs and an array of target error codes target_codes, return a dictionary mapping each target error code to the number of times it appears in the logs. A valid error code appears in the form ERROR_CODE=<code> within a log line. Ignore malformed lines and codes not present in target_codes.
Example 1:
Input: logs = [
"ts=1 level=INFO msg=start",
"ts=2 level=ERROR ERROR_CODE=E101 msg=timeout",
"ts=3 level=ERROR ERROR_CODE=E101 msg=retry",
"ts=4 level=ERROR ERROR_CODE=E202 msg=failed"
], target_codes = ["E101", "E202", "E999"]
Output: {"E101": 2, "E202": 1, "E999": 0}
Explanation: E101 appears twice, E202 once, and E999 does not appear.
Example 2:
Input: logs = [
"ERROR_CODE=E500",
"level=WARN msg=skip",
"ERROR_CODE=E404 extra=data",
"ERROR_CODE=E500"
], target_codes = ["E404", "E500"]
Output: {"E404": 1, "E500": 2}
Explanation: Only exact target codes are counted.
1 <= len(logs) <= 10^51 <= len(target_codes) <= 10^41 and 10^3