Put late and repeated events in the right order.

Timezone handling, replayed events and deterministic output for a small event-processing pipeline.

All work examples

The brief

Normalize a batch of timestamped events, remove equivalent replays and sort them by the actual instant. Events with equal timestamps need a consistent tie-breaker. Conflicting replays and timestamps without a timezone must be rejected.

Why this case matters

Events can arrive late, be replayed or use different timezone offsets. This exercise produces one repeatable timeline from a batch and makes the rules for duplicates and tied times explicit.

Input and output contract

The accepted fields and returned values are defined before the implementation is checked.

Input fieldRequirement
idA non-empty event ID used to identify a replay.
atAn ISO timestamp with an explicit timezone offset or Z.
typeA non-empty event type; a replay must keep the same type.
Output fieldMeaning
idOne record for each distinct, non-conflicting event ID.
atThe event instant in UTC, with six decimal places and a Z suffix.
typeThe original event type. Records are sorted by instant, then ID.

An input-to-output example

This example was checked against the included Python reference implementation.

Input records

[
  {
    "id": "paid",
    "at": "2026-01-01T10:30:00+01:00",
    "type": "paid"
  },
  {
    "id": "created",
    "at": "2026-01-01T10:00:00+01:00",
    "type": "created"
  },
  {
    "id": "created",
    "at": "2026-01-01T09:00:00Z",
    "type": "created"
  },
  {
    "id": "queued",
    "at": "2026-01-01T09:00:00Z",
    "type": "queued"
  }
]

Returned result

[
  {
    "id": "created",
    "at": "2026-01-01T09:00:00.000000Z",
    "type": "created"
  },
  {
    "id": "queued",
    "at": "2026-01-01T09:00:00.000000Z",
    "type": "queued"
  },
  {
    "id": "paid",
    "at": "2026-01-01T09:30:00.000000Z",
    "type": "paid"
  }
]

10:00 at +01:00 and 09:00 at Z describe the same instant, so the repeated created event collapses to one record. created and queued share a time and are ordered by ID; paid follows at 09:30 UTC.

A case that should fail

A timestamp such as 2026-01-01T09:00:00 has no timezone and is rejected. Reusing an ID with a different event type is also rejected.

How it works

The implementation parses timezone-aware timestamps, converts them to UTC and deduplicates by event ID. Ordering uses the timestamp followed by the ID, so rearranging the input does not change the result.

  1. Read the event timestamps

    Check the required fields and parse each timestamp. Reject invalid dates and timestamps that do not identify a timezone.

  2. Normalize and deduplicate

    Convert timestamps to UTC. Treat equivalent instants and matching event types as the same replay, even when their original offsets differ.

  3. Sort the final timeline

    Order accepted events by the actual instant. When instants match, sort by ID to make the result stable.

What we checked

The verifier covers offset conversion, conflicting replays, missing fields, invalid dates, empty batches and microsecond precision. It checks that rearranging the same input still produces the same timeline.

CheckReference result
Ordering across timezone offsetsPassed
Equivalent replays deduplicatedPassed
Conflicting replays rejectedPassed
Timezone-free timestamps rejectedPassed
Invalid dates rejectedPassed
Empty inputPassed
Missing fields rejectedPassed
Stable ordering for tied timesPassed
Microsecond precisionPassed
Input-order independencePassed

The reference implementation passed all 10 checks. The verifier also rejected a deliberately empty implementation. This confirms that the checks can detect that incorrect submission; it does not prove that every possible incorrect solution will be caught.

Run it yourself

Download and unzip the package. From its folder, run:

python verify.py

To check another implementation, use python verify.py path/to/candidate.py. No external packages or network access are required.

Scope and limitations

This example operates on a batch in memory. It does not implement streaming persistence or a distributed event system. Its checks are finite and are not a measurement of AI model performance.

The recorded run used Python 3.12.14. A Dockerfile is included for convenience, but Docker was not used for the published verification run and its base image is not digest-pinned.

Tell us what needs doing.

Share the scope, the expected volume and your timeline.
We’ll work out where our team can help.