Code RoomCount log lines by level
EasyPrep Room Coding #492

Count log lines by level

CodingAlgorithms & data structuresEntry–Mid~10 min

Your web server writes one log line per event in the format "<timestamp> <LEVEL> <message>", for example "2026-07-01T10:00:00 ERROR auth timeout". The level is always the second space-separated token. Given the log lines in order and a level name such as "ERROR", return how many lines were logged at exactly that level. Match the level token exactly — a line whose message merely mentions the word does not count.

Implement
count_level(lines: list[str], level: str) → int
Examples
in[["2026-07-01T10:00:00 ERROR auth timeout","2026-07-01T10:00:05 INFO user login","2026-07-01T10:00:09 ERROR db connect failed"],"ERROR"]out2
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
InputExpectedGot
[["2026-07-01T10:00:00 ERROR auth timeout","2026-07-01T10:00:05 INFO user login","2026-07-01T10:00:09 ERROR db connect failed"],"ERROR"]2not run yetsample