Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rate Limit Log Stream Alerts

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

Your question is Rate Limit Log Stream Alerts. 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

In Google Cloud monitoring pipelines, SRE tooling often needs to suppress duplicate alerts from noisy log streams. Given a sequence of log events sorted by timestamp, return which events should trigger an alert if the same message may only be alerted once every 10 seconds.

Formal Specification

Implement a function that takes logs, where each element is a pair [timestamp, message]:

  • timestamp is an integer number of seconds
  • message is a string
  • logs is sorted in non-decreasing order by timestamp

Return a list of booleans of the same length where result[i] is true if logs[i] should be alerted, otherwise false.

A message should be alerted if either:

  1. It has never appeared before, or
  2. Its previous alerted occurrence was at least 10 seconds earlier

Constraints

  • 1 <= len(logs) <= 10^5
  • 0 <= timestamp <= 10^9
  • 1 <= len(message) <= 100
  • logs is sorted in non-decreasing order by timestamp

Function Signature

def rate_limit_alerts(logs):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output