Exercise · beginner · 15 min
Pick one surviving record per account
Several systems sent the same account. Keep exactly one row per account using a stated tie-break order, and list every row you removed.
The rules
These rules decide what a correct result is. Your answer is checked on this dataset and on hidden datasets that follow the same rules.
Input
records(id, account, updated, priority) — all text. id is unique. account keeps its leading zeros.
updated is an ISO 8601 timestamp with an explicit offset; priority is a whole number. Both are always present and valid.
Rule
Keep one row per account. The survivor is the row with:
1. the latest updated instant (compare instants, not text: 01:00+01:00 equals 00:00Z),
2. then the higher priority,
3. then the lowest id (code-point order).
Every other row goes to exceptions with reason "duplicate".
Outputs (row order does not matter)
clean(id text, account text, updated timestamptz [UTC], priority int64)
exceptions(id text, reason text)The data
records · 13 rows, first 12 shown
| id | account | updated | priority |
|---|---|---|---|
| rllcz | 000064 | 2026-03-10T23:15:00Z | 9 |
| rsilp | 000458 | 2026-03-11T00:15:00+01:00 | 10 |
| r35yg | 000064 | 2026-02-01T00:00:00Z | 3 |
| rwy4c | 000875 | 2026-03-10T23:15:00Z | 1 |
| reqt9 | 000064 | 2026-01-15T08:00:00Z | 9 |
| r3mue | 000748 | 2026-02-01T12:30:00Z | 2 |
| rsiq7 | 000458 | 2026-02-01T00:00:00Z | 12 |
| rfk2c | 000458 | 2026-03-11T00:15:00+01:00 | 12 |
| rxvfh | 000458 | 2026-02-01T12:30:00Z | 9 |
| r06sr | 000941 | 2026-02-01T00:00:00Z | 1 |
| r4gch | 000748 | 2026-01-15T08:00:00Z | 2 |
| r8klo | 000064 | 2026-03-10T23:15:00Z | 1 |
What you practise
- deduplication
- tie-breaks
- timestamps
Your answer is also checked on hidden datasets generated from the same rules.
Sign in to bookmark this and keep private notes.