Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect Anomalous Daily Device Pings

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Detect Anomalous Daily Device Pings. Start with the requirements and the one table 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

Detect anomalous daily device pings

You are given daily ping counts from Athelas device telemetry. Write a PostgreSQL query that flags anomalous days per device by comparing each day to the previous available day and by detecting gaps in the daily sequence. Return one row per device-day with the current count, the previous count, the day-over-day change, a gap flag, and an anomaly label. Treat a day as anomalous when the ping count changes by more than 50% versus the previous available day, or when there is a gap of more than 1 day between consecutive records for the same device. Keep the result ordered by device and date.

Schema

device_pings
ColumnTypeDescription
device_idINTDevice identifier
ping_dateDATECalendar date of the daily ping record
ping_countINTNumber of pings recorded that day
firmware_versionVARCHAR(20)Firmware version reported that day
regionVARCHAR(50)Device region; may be NULL
Tablesdevice_pings
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results