Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Handle Missing Values and Anomalies

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

Your question is Handle Missing Values and Anomalies. 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

Nuna analytics workflows receive care records that may omit required fields or contain invalid numeric measurements. Write a function that returns a cleaned copy of the records and a report describing every missing value or anomaly.

A record is a dictionary. A field is missing when it is absent or its value is None. A numeric field is anomalous when it falls outside its inclusive [minimum, maximum] range. Replace every missing or anomalous field with None, preserve all other fields, and do not mutate the input list or its records.

Formal Specification

Implement clean_records(records, required_fields, bounds):

  • records is a list of dictionaries.
  • required_fields is a list of field names that every record should contain.
  • bounds is a dictionary mapping selected numeric field names to [minimum, maximum] values.
  • Return a dictionary with:
    • cleaned: the corrected list of records.
    • issues: a list of dictionaries containing record_index, field, and issue, where issue is either "missing" or "out_of_range".

Process fields in required_fields order and records in input order. For an out-of-range value, report only "out_of_range". Fields not listed in required_fields should remain unchanged.

Constraints

  • 0 <= len(records) <= 10^5
  • 1 <= len(required_fields) <= 100
  • Each record contains at most 100 fields
  • Bounded values are integers or floats when present
  • Minimum bounds are no greater than maximum bounds

Function Signature

def clean_records(records, required_fields, bounds):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output