Seat assignments are stored as an event log rather than a table, and the log is replayed to rebuild who currently holds a seat. The events reach you unsorted because they are read from several partitions at once; seq is the true order.
Each event has seq (int), org_id (int), user_id (str) and action, which is either ASSIGN or REVOKE.
Return one dict per organisation, with keys in this order:
org_id, seats, users
seq; seq is uniqueusers is the list of holders, sorted ascending; seats is how many there areorg_idevents| seq | action | org_id | user_id |
|---|---|---|---|
| 1 | ASSIGN | 1 | ana |
| 2 | ASSIGN | 1 | bo |
| 3 | ASSIGN | 2 | cy |
| 4 | REVOKE | 1 | ana |
| org_id | seats | users |
|---|---|---|
| 1 | 1 | ["bo"] |
| 2 | 1 | ["cy"] |
events| seq | action | org_id | user_id |
|---|---|---|---|
| 3 | ASSIGN | 5 | dee |
| 1 | ASSIGN | 5 | dee |
| 2 | REVOKE | 5 | dee |
| org_id | seats | users |
|---|---|---|
| 5 | 1 | ["dee"] |
Community-reported interview topic. Not an official company question and no affiliation is implied.
Run against the public tests, or submit to score against all of them.