Signals

Status class counts, with a bug

Summarize normalized access-log records for an incident report. Count records in each HTTP status class.

In production

Status codes land in dashboards as class counts. A wrong bucket makes a 5xx spike look like a 4xx or hides it.

What it must return

Map each status into its hundred-class and count how many records fall in each class that appears.

  • Each record has integer status from 100 to 599. Return only observed classes as string keys such as "2xx".
  • Do not mutate input values. Use the Python standard library only.

Edge cases

  • Integer division by 100 is the class key.
  • Classes with zero count must not appear.
  • Do not mutate the input list.

Signature

count_statuses(records)

This version runs but gets some cases wrong. Run the examples first to see which case fails.

Hints

  1. Second hint

  2. A partial sketch

The reference solution opens after the last hint.

Adapted from Baodium Interview Coach.

solution.py · Python

Loading editor…

Mixed responses

records

[
  {
    "status": 200
  },
  {
    "status": 204
  },
  {
    "status": 503
  }
]

Expected

{
  "2xx": 2,
  "5xx": 1
}

Each run uses a fresh Python runtime in this browser, with a 3-second limit and a Stop button. The first run downloads the runtime. 0 of 12 in Signals passed in Python on this device.

Next: Remaining error budget, partly written