cswork / libraryOpen practice workspace

Coding questions · Adobe

Solve SQL and Python Data Manipulation Tasks

This question evaluates proficiency in SQL event-log aggregation and basic Python data-structure transformations, assessing competencies such as counting distinct users, identifying frequent event types, and performing dictionary/list/string manipulations.

UserEvents

+----+---------+------------+------------+
| id | user_id | event_type | event_date |
+----+---------+------------+------------+
| 1  | 101     | install    | 2023-05-01 |
| 2  | 101     | open_app   | 2023-05-01 |
| 3  | 102     | install    | 2023-05-01 |
| 4  | 103     | install    | 2023-05-02 |
| 5  | 103     | share      | 2023-05-02 |
+----+---------+------------+------------+
Scenario

Technical screen requiring simple SQL queries and basic Python data-structure manipulations on app event data.

Question

SQL:

  1. Count distinct daily active users.
  2. Return the three most common event_type values yesterday.
  3. List users whose first recorded event was 'install'. Python: a) Given a dict, produce an inverted dict (values→keys). b) Remove duplicates from a list in one line. c) Reverse a string in one line.
Hints

Use GROUP BY with DISTINCT, ORDER BY … DESC LIMIT, window/aggregation for first_event; in Python leverage dict comprehensions, set(), slicing[::-1].

Daily active users and event-type analysis

Given the UserEvents table, return one combined result set for three event analyses.

Use columns result_set, event_date, dau, event_type, events, and user_id:

  1. result_set = 'daily_active_users': count distinct active users by event_date.
  2. result_set = 'top_event_types_2025_05_31': return the three most common event_type values on DATE '2025-05-31', ordered by event count descending and event_type ascending.
  3. result_set = 'first_event_install_users': list users whose first recorded event was 'install', using event_date then id as the tie-break order.

Fields that do not apply to a row should be NULL.

Table UserEvents

columntypeconstraints
idINTEGERPRIMARY KEY
user_idINTEGERNOT NULL
event_typeVARCHAR(50)NOT NULL
event_dateDATENOT NULL

Sample data:

event_dateevent_typeiduser_id
2023-05-01install1101
2023-05-01open_app2101
2023-05-01install3102
2023-05-02install4103
2023-05-02share5103
2025-05-30install6201
2025-05-31open_app7201
2025-05-31install8202
2025-05-31share9203
2025-06-01open_app10202

Expected output

One combined result set: DAU by date, top event types for 2025-05-31, and users whose first recorded event was install.

dauevent_dateevent_typeeventsresult_setuser_id
22023-05-01NULLNULLdaily_active_usersNULL
12023-05-02NULLNULLdaily_active_usersNULL
12025-05-30NULLNULLdaily_active_usersNULL
32025-05-31NULLNULLdaily_active_usersNULL
12025-06-01NULLNULLdaily_active_usersNULL
NULLNULLinstall1top_event_types_2025_05_31NULL
NULLNULLopen_app1top_event_types_2025_05_31NULL
NULLNULLshare1top_event_types_2025_05_31NULL
NULLNULLNULLNULLfirst_event_install_users101
NULLNULLNULLNULLfirst_event_install_users102
NULLNULLNULLNULLfirst_event_install_users103
NULLNULLNULLNULLfirst_event_install_users201
NULLNULLNULLNULLfirst_event_install_users202

Hints

  1. Use COUNT(DISTINCT user_id) for DAU.
  2. Tie-break top event types deterministically when counts are equal.
  3. Use ROW_NUMBER to identify each user's first event.