Log level frequency breakdown
A CI pipeline emits log lines of the form "<timestamp> <LEVEL> <message>". The on-call engineer wants a quick severity breakdown of a run. Given the lines, return a dictionary mapping each level that actually appears (for example "INFO", "WARN", "ERROR") to the number of lines logged at that level. Levels that never appear must not be keys in the result, and an empty log yields an empty dictionary.
Implement
level_counts(lines: list[str]) → dict[str,int]Examples
in
[["t1 ERROR db down","t2 INFO retrying now","t3 ERROR db down"]]out{"INFO":1,"ERROR":2}What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 10 min
solution.py
InputExpectedGot
[["t1 ERROR db down","t2 INFO retrying now","t3 ERROR db down"]]{"INFO":1,"ERROR":2}not run yetsample