PIXELBANKv8.2.1
Menu

Alert Deduplication with Flap Suppression

Problem Statement

Process a stream of alert state changes and count how many notifications should actually be sent, suppressing rapid flapping using a dampening window.

Background

Alerts fire ("firing") and resolve ("resolved"). A notification is sent when an alert transitions into firing from a non-firing state — but only if at least cooldown seconds have passed since the last notification for that alert key. Transitions to resolved never notify (in this model). Repeated firing events while already firing do not notify. Each event is (key, state, time), processed in time order.

Your Task

def count_notifications(events, cooldown):

Return the number of notifications sent (int).

Input Format

  • events: list of (key, state, time), time non-decreasing; cooldown (int).

Output Format

  • A single int.

Sample

evts = [("db","firing",0),("db","resolved",5),("db","firing",100)]
print(count_notifications(evts, 60))

Output:

2

Example:

Input:
evts = [("db","firing",0),("db","resolved",5),("db","firing",100)]
print(count_notifications(evts, 60))
Output:
2
Reasoning:

Fire at 0 notifies; resolve at 5 no; re-fire at 100 (>=60 since last) notifies. Total 2.

Constraints:

  • Notify only on a transition into firing from non-firing.
  • Suppress if time - last_notify[key] < cooldown.
  • Track per-key current state and last notify time; resolved never notifies.
Editor

Test Results

0/0
Run code to see test results.
Alert Deduplication with Flap Suppression - Hard | PixelBank