Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Mobile Chat Event Ordering

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Mobile Chat Event Ordering. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a list of chat events for a mobile messaging system, reconstruct the visible conversation state. Each event is one of: send, deliver, read, edit, or delete, and includes a message_id, timestamp, and optional fields such as text or user_id. Events may arrive out of order and may be duplicated. Return the final ordered list of non-deleted messages with their latest text and highest status (sent < delivered < read).

Constraints

  • 1 <= len(events) <= 2 * 10^5
  • Each event is [event_type, message_id, timestamp, payload]
  • event_type is one of send, deliver, read, edit, delete
  • 0 <= timestamp <= 10^9
  • Duplicate events may appear and events may arrive in any order

Function Signature

def reconstruct_chat(events):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output