Easy · System Design
Log analyzer
Given log lines fed one at a time to ingest(line), return report(): a map holding TOTAL, the number of lines ingested, plus the number of lines at each level seen. A line's level is its first whitespace-separated token, upper-cased, with one trailing colon removed; blank lines have no level.
Examples
Example 1
{
"lines": ["INFO: started", "WARN: slow query", "ERROR: timeout", "INFO: retry ok"]
}Output: TOTAL=4, INFO=2, WARN=1, ERROR=1
Example 2
{
"lines": ["warn: disk at 91", "", "INFO retry ok", "Warn: disk at 95", "ERROR: db: timeout"]
}Output: TOTAL=5, WARN=2, INFO=1, ERROR=1
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.