Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
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

Your question is Stream Validation Function. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.