Count events per minute

Python data engineering interview problem. Difficulty: beginner. Pattern: Dictionaries. About 10 minutes. Free to practice.

Group stream events into one-minute buckets and count how many fall in each bucket. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

A stream delivers events, each with a timestamp in whole seconds since the start of the stream. Implement events_per_minute(timestamps). Put each event in the minute it belongs to: seconds 0 to 59 are minute 0, seconds 60 to 119 are minute 1, and so on. Return a dict that maps the minute number to the number of events in that minute. Leave out minutes that have no events. Keys appear in increasing minute order.

Requirements

  • Minutes with no events are not in the result.
  • Keys are in increasing minute order.

Constraints

  • Timestamps are non-negative integers.
  • The input list is not changed.

Examples

Input: events_per_minute([5, 59, 60, 125]) Output: {0: 2, 1: 1, 2: 1} Seconds 5 and 59 are minute 0, 60 is minute 1 and 125 is minute 2.

Topics: lakebench, python, stream, tumbling, window, event.

More Python interview questions · All interview problems · Learn data engineering

beginner

Count events per minute

Interview-style drill: Group stream events into one-minute buckets and count how many fall in each bucket.

A stream delivers events, each with a timestamp in whole seconds since the start of the stream. Implement `events_per_minute(timestamps)`. - Put each event in the minute it belongs to: seconds 0 to 59 are minute 0, seconds 60 to 119 are minute 1, and so on. - Return a dict that maps the minute number to the number of events in that minute. - Leave out minutes that have no events. - Keys appear in increasing minute order.