Practice/Netflix/User Engagement Patterns
User Engagement Patterns
CodingMust
Problem Overview
You are analyzing user engagement patterns across different Netflix content to understand viewing behavior. This type of analysis helps Netflix optimize content recommendations and understand completion rates.
Given a list of viewing sessions, you need to:
- Classify each session based on percentage watched
- Find each user's dominant engagement pattern
- Count how many users have each dominant pattern
Engagement Classification Rules
- Abandoned: Watched less than 25% of the content
- Sampled: Watched 25% to 75% of the content (inclusive on both ends)
- Completed: Watched more than 75% of the content
Example
`
viewing_data = [
{"account_id": "U1", "title_id": "T1", "title_runtime_secs": 3600, "watched_secs": 3500, "day_nbr": 1},
{"account_id": "U1", "title_id": "T2", "title_runtime_secs": 5400, "watched_secs": 5000, "day_nbr": 3},
{"account_id": "U2", "title_id": "T1", "title_runtime_secs": 3600, "watched_secs": 800, "day_nbr": 5},
{"account_id": "U2", "title_id": "T2", "title_runtime_secs": 2700, "watched_secs": 500, "day_nbr": 9},
{"account_id": "U3", "title_id": "T1", "title_runtime_secs": 3600, "watched_secs": 1800, "day_nbr": 2}
]
Analysis:
U1: 3500/3600 = 97% (Completed), 5000/5400 = 93% (Completed) → dominant: Completed
U2: 800/3600 = 22% (Abandoned), 500/2700 = 19% (Abandoned) → dominant: Abandoned
U3: 1800/3600 = 50% (Sampled) → dominant: Sampled
analyzeEngagementPatterns(viewing_data)
Returns {"Completed": 1, "Abandoned": 1, "Sampled": 1}
`
Requirements
- Calculate percentage watched for each session
- Classify each session correctly based on percentage
- Handle boundary cases (exactly 25% or 75%)
- Find the most common pattern for each user
- Handle ties (any tied pattern can be chosen as dominant)
- Return counts grouped by dominant pattern
Constraints
- 1 <= viewing_data.length <= 10^5
- 1 <= title_runtime_secs <= 10^6
- 0 <= watched_secs <= title_runtime_secs
- All account_id and title_id values are non-empty strings