Workspace/Coding labs
Loading progress

Apply repeated events exactly once locally

Intermediate65 min

Reduce events with source, id, account, and signed integer delta. Identity is the pair (source,id). Apply the first occurrence, ignore identical repeats, and reject a repeated identity with a different account or delta. Return account balances; negative balances are allowed because these are general counters, not financial accounts. Validate nonempty string identities and integer deltas excluding booleans. This is an in-memory projection exercise, not a claim of end-to-end exactly-once delivery.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Inputs1/1 adds 3 to x, then identical s1/1

Output{'x':3}

Delivery repeats do not create new intent.
EXAMPLE 2

Inputs1/1 adds 3 and s2/1 adds 4

Output{'x':7}

Source namespaces distinguish event identities.
solution.pyPython 3.12