Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Sliding window unique visitor count

Python data engineering interview problem. Difficulty: advanced. Pattern: Sliding Window. About 20 minutes. Part of the Pro drill bank.

An analytics job counts distinct visitors inside each sliding window of events so a spike of one user does not look like a crowd.

Return the distinct-visitor count for each window of a given size.

Requirements

  • Each result corresponds to one window position.
  • Counts are distinct ids, not raw events.

Constraints

  • events: visitor ids in time order.
  • window: window length.
  • Windows that run off the end should follow the tests.
  • Repeats inside a window count once.

Examples

Input: distinct_in_windows([(1, 'a'), (2, 'b'), (8, 'a')], 5) Output: [1, 2, 1] This input follows the stated rules and produces this output.

Topics: lakebench, python, sliding-window.

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

advanced

Sliding window unique visitor count

Interview-style drill: For a stream of timestamped visitor ids, report the count of distinct visitors in every trailing 60-second window.

Return the distinct-visitor count for each window of a given size.