Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
Normalize Sensor Data And Detect Anomalies
00:00
5 left

Normalize Sensor Data And Detect Anomalies

HardPython

Problem

MarshBerry's monitoring pipeline receives chronological sensor readings as timestamped numeric values. Implement a function that min-max normalizes all readings and identifies values that are anomalous compared with the preceding readings.

For each reading, use up to the previous window readings as its baseline. A reading is anomalous when the baseline contains at least two values and either the baseline standard deviation is zero while the current value differs from the baseline mean, or the absolute difference from the baseline mean is greater than threshold * standard_deviation. Use population standard deviation. The current reading must not be included in its own baseline.

Return a dictionary with normalized, a list of normalized values rounded to four decimal places, and anomalies, a list of zero-based indices. Normalize using (value - minimum) / (maximum - minimum). If all values are equal, every normalized value is 0.0.

Formal Specification

Input readings is a non-empty list of dictionaries with integer timestamp and numeric value fields. Input timestamps are chronological. window is a positive integer, and threshold is a positive number. Return {"normalized": list[float], "anomalies": list[int]}.

Constraints

  • 1 <= len(readings) <= 10^5
  • 1 <= window <= len(readings)
  • threshold > 0
  • -10^9 <= reading['value'] <= 10^9
  • Timestamps are integers in nondecreasing order

Function Signature

def normalize_and_detect(readings, window, threshold):
Interviewer

Your question is Normalize Sensor Data And Detect Anomalies. 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.