Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Parse and Order Event Streams

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

Your question is Parse and Order Event Streams. 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

Hudl receives sports telemetry events from recording and analysis surfaces. Events can arrive out of order, and some events may omit their timestamp attribute. Implement a function that returns the events in playback order.

An event is represented as a dictionary. A timestamp, when present, is a non-negative integer measured in milliseconds. Apply these ordering rules:

  1. Events with timestamps come first, ordered by ascending timestamp.
  2. Events without a timestamp key come after all timestamped events.
  3. Events with equal timestamps, and events without timestamps, retain their original input order.
  4. Return the original event dictionaries in a new list. Do not modify the input list or its dictionaries.

Formal Specification

Implement order_telemetry(events), where events is a list of dictionaries and each dictionary contains an event key and may contain a timestamp key. Return a new list containing the same dictionaries in the required order.

Constraints

  • 0 <= len(events) <= 10^5
  • Each event contains an event key
  • A present timestamp is an integer from 0 through 10^12
  • The input list and event dictionaries must not be mutated

Function Signature

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