Practice Analyze Subscription Conversion
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Table UserActivity has user_id INT, activity_date DATE, activity_type VARCHAR, and activity_duration INT in minutes. Include users with both free_trial and paid activity. Return user_id, trial_avg_duration, and paid_avg_duration, rounding each average over its recorded activity days to two decimals. Ignore cancelled rows in both averages; a later cancellation does not erase a prior conversion. Sort by user_id ascending. Practice approach: Group by user and conditionally average the two relevant activity types, leaving other rows NULL rather than zero. Require both groups to exist. Do not divide by seven or synthesize missing trial days: the source example averages only recorded rows.
Source: Analyze Subscription Conversion on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
{
"UserActivity": [
{
"user_id": 1,
"activity_date": "2026-01-01",
"activity_type": "free_trial",
"activity_duration": 10
},
{
"user_id": 1,
"activity_date": "2026-01-03",
"activity_type": "free_trial",
"activity_duration": 21
},
{
"user_id": 1,
"activity_date": "2026-01-10",
"activity_type": "paid",
"activity_duration": 40
},
{
"user_id": 1,
"activity_date": "2026-01-12",
"activity_type": "cancelled",
"activity_duration": 0
},
{
"user_id": 2,
"activity_date": "2026-01-01",
"activity_type": "free_trial",
"activity_duration": 20
},
{
"user_id": 2,
"activity_date": "2026-01-10",
"activity_type": "cancelled",
"activity_duration": 0
}
]
}[
{
"user_id": 1,
"trial_avg_duration": 15.5,
"paid_avg_duration": 40
}
]User 1 converted before cancelling, so the averages are 15.50 and 40.00. User 2 never had paid activity.
Constraints
Related LeetCode Problems
Practice more problems similar to Analyze Subscription Conversion .
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.