Month-1 Retention by Cohort

Hard ⏱ 18 min 25% acceptance ★★★★☆ 4.3
Users are (user_id, signup_month, active_months) where active_months is a set of month numbers. Write retention_by_cohort(users) returning a dict mapping each signup month to the percentage (1-decimal) of that cohort active in signup_month + 1.

Examples

Example 1
Input
retention_by_cohort([(1, 0, {0, 1}), (2, 0, {0}), (3, 1, {1, 2})])
Output
{0: 50.0, 1: 100.0}
Explanation

Cohort 0: one of two returned in month 1. Cohort 1: its single user returned.

Constraints

  • Group by signup_month.
  • Retained = signup_month + 1 in active_months.

Topics

Business Logiccohort analysis

Companies

AmplitudeMixpanelCleverTap

Hints

Hint 1

Two dicts: cohort sizes and retained counts.

Hint 2

Round at the end per cohort.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.