DataDriven
LearnPracticeInterviewDiscussDailyJobs

The Event Window

A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.

Domain
Python
Difficulty
medium
Seniority
L4

Problem

A request-tracking service for an API needs to answer one question on demand: how many hits landed in the last five minutes. Implement a `HitCounter` whose `hit(timestamp)` records an event at the given second and whose `get_hits(timestamp)` returns how many recorded events fall inside the trailing 300-second window ending at and including `timestamp`, so a hit at exactly `timestamp - 300` has already aged out. Timestamps arrive in non-decreasing order. Then implement the graded entrypoint `event_window(operations, arguments)`: given a list of operation names (`"HitCounter"`, `"hit"`, `"get_hits"`) and a parallel list of argument lists, replay them against a single counter and return one result per operation, `None` for `"HitCounter"` and `"hit"` and the integer count for each `"get_hits"`.

Summary

A five-minute window is all that matters.

Practice This Problem

Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.

Related

  • All Practice Problems
  • Mock Interview Mode
  • Python Interview Questions
  • Data Engineering Interview Prep Guide
  • Daily Challenge
  • Data Engineering Lessons