Fix the monthly active users count

Review the AI's codeEasy12 minSnowflake and Databricks style

Your task

An agent wrote a 40-line SQL query for monthly active users, a number that goes to the board. The numbers look plausible, but nobody on the team can follow the joins. Before trusting it, you compute the same metric a second, simpler way, straight from the raw events, and compare.

An assistant wrote distinct_active_users(event_rows) as that second count. It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • event_rows: one event per row, written user_id|date, with the date as YYYY-MM-DD.
  • Return one YYYY-MM=count string per month that has an active user, sorted by month.

Rules the tests check:

  • Split each row at its first |. Skip a row with no | or with an empty user id.
  • The month is the first 7 characters of the date: 4 digits, -, then 2 digits from 01 to 12. Skip a row whose date does not start that way. The rest of the date is not checked.
  • A month's count is the number of different users with at least one event in it. A user counts once per month, however many rows they have in that month.
  • User ids compare exactly: case and spaces matter.

Examples

distinct_active_users(event_rows: list[str]) -> list[str]
Example 1
Inputdistinct_active_users(["u1|2026-01-15", "u2|2026-01-20", "u1|2026-01-31"])
Output["2026-01=2"]
Example 2
Inputdistinct_active_users(["u1|2026-01-15", "u1|2026-01-15"])
Output["2026-01=1"]
Example 3
Inputdistinct_active_users(["u1|2026-01-31", "u1|2026-02-01"])
Output["2026-01=1", "2026-02=1"]