HTTP status code classes
An API gateway access log has one line per request: "<timestamp> <method> <path> <status>", where status is a three-digit HTTP code like 200 or 503. For a traffic summary, group codes into classes by their first digit: "2xx", "3xx", "4xx", "5xx", and so on. Return a dictionary mapping each class that occurs in the log to its request count. Classes with no requests must be absent, and an empty log returns an empty dictionary.
Implement
status_class_counts(lines: list[str]) → dict[str,int]Examples
in
[["t1 GET /home 200","t2 GET /missing 404","t3 POST /pay 500","t4 GET /home 204"]]out{"2xx":2,"4xx":1,"5xx":1}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 GET /home 200","t2 GET /missing 404","t3 POST /pay 500","t4 GET /home 204"]]{"2xx":2,"4xx":1,"5xx":1}not run yetsample