Host Message SLA
EasySimulation · Airbnb
Airbnb tracks how quickly hosts answer guests. You receive messages from many conversation threads as rows [thread_id, sender, timestamp], sorted by timestamp (non-decreasing; rows with equal timestamps are processed in the given order). sender is either "guest" or "host".
Each thread is either idle or waiting for a host reply, starting idle:
- A guest message makes an idle thread start waiting, with the clock started at that message's timestamp. A guest message on a thread that is already waiting does not restart the clock.
- A host message on a waiting thread ends the wait. If
host_timestamp - wait_start > deadline, that wait counts as one violation. A host message on an idle thread does nothing. - After all messages are processed, any thread still waiting counts one more violation if
now - wait_start > deadline; if not, it is still within its SLA and does not count.
Return [thread_id, violation_count] for every thread that appears in messages (including threads with 0 violations), sorted by thread_id in ascending string order.
Example 1
- Input:
- messages = [['t1', 'guest', 0], ['t2', 'guest', 3], ['t1', 'guest', 8], ['t2', 'host', 9], ['t1', 'host', 12], ['t1', 'guest', 20]], deadline = 10, now = 26
- Output:
- [['t1', 1], ['t2', 0]]
- Explanation
- Thread t1 starts waiting at 0; the second guest message at 8 does not reset the clock, so the reply at 12 is 12 > 10 late: one violation. Its final guest message at 20 has waited only 6 by
now = 26. Thread t2 is answered after 6, which is on time.
Example 2
- Input:
- messages = [['a', 'host', 1], ['a', 'guest', 2], ['b', 'guest', 4]], deadline = 5, now = 8
- Output:
- [['a', 1], ['b', 0]]
- Explanation
- The host message on idle thread a does nothing. At the end, a has been waiting 8 - 2 = 6 > 5 (a violation) while b has waited only 4.
Example 3
- Input:
- messages = [['x', 'guest', 5], ['x', 'host', 15]], deadline = 10, now = 15
- Output:
- [['x', 0]]
- Explanation
- The reply takes exactly 10, and only strictly more than
deadlineis a violation.
Constraints
0 <= messages.length <= 10^50 <= timestamp <= now <= 10^9, andnowis at least the last message timestamp0 <= deadline <= 10^9senderis"guest"or"host"