Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
Stream Validation Function
00:00
5 left

Stream Validation Function

MediumPython

Problem

Alaska Airlines Mileage Plan receives user profile events as an ordered stream. Write a function that accepts valid events while identifying malformed, duplicate, or out-of-order data.

An event is valid when it contains event_id, user_id, email, and occurred_at; both identifiers are non-empty strings; email contains exactly one @ with a non-empty local part and a domain containing a period; and occurred_at is a non-negative integer. An event is also invalid if its event_id was already accepted or if its timestamp is not strictly later than the most recently accepted event for the same user. Rejected events must not update validation state.

Formal Specification

Implement process_user_stream(events). The input is a list of dictionaries. Return a dictionary with accepted, the original valid event dictionaries in input order, and rejected_indices, the zero-based indices of invalid events in input order.

Extra fields are allowed and must be preserved. The input stream is already ordered, so do not sort it.

Constraints

  • 1 <= len(events) <= 100000
  • Each event contains at most 20 fields
  • event_id and user_id are intended to be non-empty strings
  • occurred_at must be a non-negative integer
  • Rejected events do not update duplicate or timestamp state
  • Extra fields are allowed and must be preserved

Function Signature

def process_user_stream(events):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.