PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates streaming data processing skills, sliding-window counting algorithms, and efficient online state management for metric monitoring.

  • medium
  • Meta
  • Coding & Algorithms
  • Site Reliability Engineer

Implement a Streaming VMStat Alert

Company: Meta

Role: Site Reliability Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Write a command-line program that reads a continuous stream of `vmstat`-style output from standard input and raises an alert based on a sliding time window. The program is invoked as: `myscript <metric_name> <threshold> <max_exceed_count> <window_seconds>` Example: `vmstat 1 | myscript us 100 50 300` Requirements: 1. The input begins with a header row containing metric names, such as `us`, `sy`, `id`, and so on. 2. Each subsequent row is one sample collected once per second. 3. Monitor the metric named by `metric_name`. 4. A sample is considered abnormal if the metric value is greater than `threshold`. 5. Maintain a sliding window covering only the most recent `window_seconds` samples. 6. If the number of abnormal samples in the current window becomes greater than `max_exceed_count`, print the abnormal samples from that window. 7. The program should process the stream online without storing unbounded history. Assume the input is whitespace-delimited and that the target metric always exists in the header.

Quick Answer: This question evaluates streaming data processing skills, sliding-window counting algorithms, and efficient online state management for metric monitoring.

Implement the core logic of a command-line alerting tool for vmstat-style data. For this coding problem, write a function that receives the input stream as a list of strings. The first non-empty line is a whitespace-delimited header containing metric names such as us, sy, id, etc. Each following non-empty line is one sample collected once per second. Monitor the column named by metric_name. A sample row is abnormal if that metric's value is strictly greater than threshold. Maintain a sliding window containing only the most recent window_seconds samples. Whenever the number of abnormal samples in the current window transitions from less than or equal to max_exceed_count to greater than max_exceed_count, emit an alert containing all abnormal sample rows currently in that window, in chronological order. Return all emitted alerts. Each alert is a list of the original sample row strings. If no alert is ever triggered, return an empty list. Your solution should process the stream online and should not keep unbounded history.

Constraints

  • 1 <= len(lines) <= 200000, and lines[0] is the header row if present
  • 1 <= window_seconds <= 200000
  • 0 <= max_exceed_count <= window_seconds
  • The target metric always exists in the header
  • Each sample row has the same number of whitespace-delimited fields as the header
  • Metric values are numeric

Examples

Input: (['us sy id', '90 5 5', '110 5 5', '120 6 4', '80 10 10'], 'us', 100, 1, 3)

Expected Output: [['110 5 5', '120 6 4']]

Explanation: The second and third samples are abnormal. When the third sample arrives, the 3-sample window contains 2 abnormal rows, which is greater than 1, so one alert is emitted.

Input: (['us sy', '101 1', '102 1', '50 1', '130 1', '140 1'], 'us', 100, 1, 2)

Expected Output: [['101 1', '102 1'], ['130 1', '140 1']]

Explanation: With a 2-sample window, rows 1 and 2 trigger the first alert. The alert clears when the count drops back to 1, then rows 4 and 5 trigger a second alert.

Input: (['us sy id'], 'us', 10, 0, 5)

Expected Output: []

Explanation: There are no sample rows after the header, so no alert can be triggered.

Input: (['us sy', '100 1', '101 1', '100 1'], 'us', 100, 0, 2)

Expected Output: [['101 1']]

Explanation: A value equal to the threshold is not abnormal because the comparison is strictly greater than. Only the middle row is abnormal, so exactly one alert is emitted.

Input: (['us sy id', '150 0 0', '20 0 80', '20 0 80', '160 0 0'], 'us', 100, 1, 2)

Expected Output: []

Explanation: The first abnormal sample falls out of the 2-sample window before the last abnormal sample arrives, so the abnormal count never becomes greater than 1.

Hints

  1. Because samples arrive once per second, you can treat the row number as the timestamp and use it to expire old samples.
  2. You do not need to store every sample. Keeping only abnormal samples that are still inside the current window is enough to know when an alert should fire.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)