Most Popular Active Plan for the Top Event Type
Updated
Problem statement
First find the event type with the most event rows. Break an event-type tie alphabetically.
For events of that type, join the subscription active at each event time and return the plan with the most matching events. A subscription is active when start_time <= event_time < end_time; a null end_time means it is still active. Break a plan tie alphabetically. Return plan_type and event_count.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
events
| Column | Type | Nullable | Description |
|---|---|---|---|
| event_idPK | Integer | No | — |
| user_id | Integer | No | — |
| event_type | Text | No | — |
| event_time | Timestamp | No | — |
subscriptions
| Column | Type | Nullable | Description |
|---|---|---|---|
| subscription_idPK | Integer | No | — |
| user_id | Integer | No | — |
| plan_type | Text | No | — |
| start_time | Timestamp | No | — |
| end_time | Timestamp | Yes | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| plan_type | Text | No | — |
| event_count | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- At most one subscription is active for a user at any event time.
- The selected top event type has at least one event with an active subscription.
- The end boundary is exclusive.
More Notion interview questions
- Nested Todo ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Mutable Table AggregationsPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2026
- Block Type with the Most ChildrenPHONE SCREEN · Seen Mar 2026
- Country with the Most EventsPHONE SCREEN · Seen Mar 2026
- Event Type with the Most EventsPHONE SCREEN · Seen Mar 2026
- Page Permission InheritancePHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
- Percentage of Blocks Never EditedPHONE SCREEN · Seen Mar 2026
- Text Document HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
- Versioned Document StorePHONE SCREEN · Seen Apr 2025
- Top Error Types in a Time WindowONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- Parquet-Like Columnar Format OperationsJump Trading · PHONE SCREENJump Trading interview questions
- Nth Highest SalaryPaytm · PHONE SCREENPaytm interview questions
- Email Funnel: Opened Within a Day, Replied Within a WeekSuperhuman · PHONE SCREENSuperhuman interview questions
- Employees Who Earn More Than Their ManagersNykaa · PHONE SCREENNykaa interview questions
- Employees Who Joined More Than a Week AgoNewgen Software · PHONE SCREEN
- Departments Without EmployeesDell Technologies · PHONE SCREENDell Technologies interview questions
- Second-Highest Distinct SalaryChubb · PHONE SCREENChubb interview questions
- Swap Two Gender ValuesInfosys · PHONE SCREENInfosys interview questions
- Find Rows Common to Two TablesSalesforce · PHONE SCREENSalesforce interview questions
- Count Records Present in A but Not BCapital One · PHONE SCREENCapital One interview questions