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
Detect Anomalies in Event Streams
00:00
5 left

Detect Anomalies in Event Streams

HardSQL · PostgreSQL

Problem

Write a function to identify anomalies and missing data points across distributed event streams without writing inefficient or unindexed queries.

Use the provided stream definitions and event records over the parameterized monitoring interval. Return every expected point that is missing or anomalous, while excluding inactive streams and events outside the interval.

Output

  1. One row per affected stream and expected timestamp.
  2. Columns: stream_id, expected_at, anomaly_type, event_count, first_event_at, and last_event_at.
  3. Include missing, duplicate, null_value, or out_of_range anomalies, ordered by stream_id, expected_at, and anomaly_type.

Schema

event_streams
ColumnTypeDescription
stream_idPKVARCHAR(40)Unique event stream identifier
source_regionVARCHAR(30)Region producing the stream
expected_interval_secondsINTExpected interval between data points
minimum_valueDECIMAL(10,2)Allowed minimum event value
maximum_valueDECIMAL(10,2)Allowed maximum event value
is_activeBOOLEANWhether the stream should be monitored
stream_events
ColumnTypeDescription
event_idPKBIGINTUnique event identifier
stream_idVARCHAR(40)Referenced event stream
event_timeTIMESTAMPTZTime at which the event was received
event_typeVARCHAR(30)Event classification
event_valueDECIMAL(10,2)Measured event value
Tablesevent_streamsstream_events
Interviewer

Your question is Detect Anomalies in Event Streams. Start with the requirements and the two tables 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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.