#110

User Engagement Patterns

MEDIUMHash TablePYTHON

Problem Description

A user analytics pipeline classifies streaming session engagement and rolls up user-level behavioral segments — a foundational step in retention and recommendation modeling. Given a list of session records, perform a three-part engagement analysis. **Input:** A list `sessions` of dicts with `user_id`, `title_id`, `watch_time`, and `title_runtime`. **Output:** A 3-tuple: (1) list of per-session engagement labels, (2) dict mapping each user to their most frequent label, (3) dict counting users per label across all three categories. **Key Rules:** - Watch percentage = `watch_time / title_runtime * 100`. - Label thresholds: ≤25% → `'Abandoned'`; >25% and ≤75% → `'Sampled'`; >75% → `'Completed'`. - On ties for a user's most frequent label, choose alphabetically first (`Abandoned < Completed < Sampled`). - Part 3 counts users (not sessions); always include all three keys even if count is 0.

Topics

arraydata analysis

Asked at Companies

netflix

Solve This Problem

Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.

Start Solving →