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
Clean and Normalize Data Streams
00:00
5 left

Clean and Normalize Data Streams

HardPython

Problem

Amgen's laboratory systems can emit sample events with inconsistent field names, capitalization, whitespace, timestamp formats, and numeric units. Implement normalize_stream to clean a batch of incoming event records and return only valid, canonical events.

Formal Specification

Input is a list of dictionaries. Each record may use these aliases:

  • Event ID: event_id or id
  • Sample ID: sample_id or sample or specimen_id
  • Status: status or state
  • Dose: dose_mg or dose
  • Timestamp: timestamp or time

Return a list of dictionaries with exactly these keys: event_id, sample_id, status, dose_mg, and timestamp.

Normalize values as follows:

  1. Trim identifier whitespace and convert identifiers to strings.
  2. Convert statuses to lowercase and map complete and completed to completed, in-progress and processing to in_progress, and failed and error to failed.
  3. Parse doses such as "12.5 mg", "1,000", or numeric values into nonnegative floats. Missing doses become None.
  4. Parse ISO-8601 timestamps. Treat timestamps without a timezone as UTC and return UTC timestamps ending in Z.
  5. Discard records missing required fields, having unknown statuses, invalid timestamps, or invalid doses.
  6. If multiple valid records share an event_id, keep the last valid record while preserving the order of each event's first appearance.

Constraints

  • 1 <= len(records) <= 10^5
  • Each record has at most 20 fields
  • Identifiers contain at most 100 characters
  • Timestamps are ISO-8601 strings, datetime values, or invalid input
  • Statuses are case-insensitive and may contain spaces, underscores, or hyphens

Function Signature

def normalize_stream(records):
Interviewer

Your question is Clean and Normalize Data Streams. 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.