Last log line by keyword
You are grepping a cron job's output by hand and want the most recent mention of a task. Each line has the form "<timestamp> <LEVEL> <message>". Given the lines in the order they were written and a keyword, return the ENTIRE last line whose message part (the text after the level token) contains the keyword as a substring — timestamp and level included in what you return. If nothing matches, return the empty string.
Implement
last_match_line(lines: list[str], keyword: str) → strExamples
in
[["2026-07-01T02:00:00 INFO backup started","2026-07-01T02:05:00 ERROR backup failed disk full","2026-07-01T03:00:00 INFO cleanup started"],"backup"]out"2026-07-01T02:05:00 ERROR backup failed disk full"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
[["2026-07-01T02:00:00 INFO backup started","2026-07-01T02:05:00 ERROR backup failed disk full","2026-07-01T03:00:00 INFO cleanup started"],"backup"]"2026-07-01T02:05:00 ERROR backup failed disk full"not run yetsample