Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rate Limit Agent Tool Calls

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

Your question is Rate Limit Agent Tool Calls. 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 a Databricks Agent Framework deployment, tool calls from multiple agents are logged as a time-ordered stream. Implement an algorithm that returns the first timestamp when any agent exceeds a sliding-window limit, using standard data structures efficiently.

Given a list of events events, where each event is [timestamp, agent_id], and integers window_size and max_calls, return the earliest timestamp at which some agent_id has made more than max_calls calls within the inclusive window [timestamp - window_size + 1, timestamp]. If no agent violates the limit, return -1.

Constraints

  • 1 <= len(events) <= 10^5
  • 1 <= window_size <= 10^9
  • 1 <= max_calls <= 10^5
  • 0 <= timestamp <= 10^9
  • events is sorted by non-decreasing timestamp
  • agent_id is a non-empty string

Function Signature

def first_rate_limit_violation(events, window_size, max_calls):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output