Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Automate an Operational Task

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

Your question is Automate an Operational Task. 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

Nielsen ONE operations periodically reviews host telemetry to identify sustained CPU pressure. Given CPU samples for multiple hosts, return one alert for every run of consecutive high-usage windows.

For each host, sort samples by timestamp. A window is high usage when the arithmetic mean of its window_size consecutive CPU readings is greater than or equal to threshold. A run qualifies when it contains at least required_windows consecutive high-usage windows. Return one alert for each qualifying run.

Formal Specification

Implement detect_resource_alerts(samples, window_size, threshold, required_windows).

  • samples is a list of dictionaries with integer host, integer timestamp, and numeric cpu fields.
  • window_size, required_windows, and timestamps are positive integers.
  • threshold and cpu are floating-point values. CPU values are percentages from 0 through 100.
  • Return a list of dictionaries, sorted by host and then start_timestamp.
  • Each alert must contain host, start_timestamp, and end_timestamp. The interval spans from the first sample in the qualifying run to the last sample in its final qualifying window.
  • If no run qualifies, return an empty list.

Constraints

  • 1 <= len(samples) <= 10^5
  • Each host has at least one sample
  • Samples for a host have unique timestamps
  • 1 <= window_size <= 10^4
  • 1 <= required_windows <= 10^4
  • window_size cannot exceed the number of samples for a host
  • 0 <= samples[i]['cpu'] <= 100

Function Signature

def detect_resource_alerts(samples, window_size, threshold, required_windows):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output