Mock contest: 6 problems
A dress rehearsal: 6 new problems you haven't seen in the labs, in the same mix the real contest is likely to have (3 SQL, 3 Python, easy β hard). The real thing is 150 minutes for 6 problems; this one is shorter, so give yourself 60 minutes and practise the strategy as much as the code.
Rules of the rehearsal
No hints, no solutions until the timer ends. In the real contest you won't have them either. Afterwards, open the reference solutions and compare. Check the explanations: they cover the traps each problem was built around.
The SQL problems run on SQLite like the SQL lab. As practice for a MySQL judge, write down in a comment
how you'd translate the date functions (date(d, '-1 month') β d - INTERVAL 1 MONTH).
Problem A Β· SQL Β· Conversion funnel
Conversion funnel
any orderβ solvedevents, return a single row views, carts, purchases, conversion_pct: the number of distinct users with at least one event of each type, and purchases / views Γ 100 rounded to 1 decimal.Problem B Β· Python Β· JSON Lines with bad records
JSON Lines with bad records
stdin β stdoutβ solved"type" and a numeric "amount" (int or float, not bool, not a string). Blank lines are ignored.
Everything else (broken JSON, arrays, missing or wrong fields) is bad.Output one line
type count total per type sorted by type (total with 2 decimals), then a final line
bad N.Problem C Β· SQL Β· Daily active users with a date spine
Daily active users incl. zero days
order mattersβ solvedday, active_users for every day from 2026-05-01 to 2026-05-07 inclusive, where active_users = distinct users in logins that day. Days without logins must appear with 0. Order by day.Problem D Β· Python Β· Messy CSV report
Messy CSV β city report
stdin β stdoutβ solvedorder_id,customer,city,amount,status. Fields may be quoted and contain
commas ("Tehran, Iran", "1,200.50").
- An order_id may appear several times: the last line wins (dedupe before filtering).
- Keep orders whose status is
completedcase-insensitively, ignoring surrounding spaces. - Skip orders with an empty amount.
city,orders,revenue (with that header) sorted by revenue desc, then city asc; revenue with 2 decimals.
Quote fields only when needed (the default of Python's csv module).Problem E Β· SQL Β· Month-over-month retention
Month-over-month retention
order mattersβ solvedmonth (YYYY-MM), active_customers, and retained = how many of those customers were also active in the previous calendar month. Order by month.Problem F Β· Python Β· Identity stitching
Identity stitching (union-find)
implement group_accounts()β solvedgroup_accounts(accounts): each account is {"id", "email", "phone"} (either may be
None). Two accounts belong to the same person if they share an email (compare stripped + lower-cased) or a
phone (compare digits only), directly or through a chain of other accounts. Values that are empty after normalising
never link anything.Return the groups as sorted lists of ids, the groups sorted by their smallest id.
Debrief
Score yourself honestly, then fix the habit rather than the bug:
| What happened | What to change in the real contest |
|---|---|
| Wrong number of rows in A or C | You counted rows instead of distinct users, or used COUNT(*) after a LEFT JOIN. Say out loud what one output row means before writing SQL. |
| B or D failed only on one test | An edge case: bools are ints in Python, empty input, dedupe before filtering. Write the edge-case list from the statement first. |
| E gave too many "retained" | You compared with the previous active month instead of the previous calendar month. Boundary definitions decide hidden tests. |
| F is missing accounts | Accounts with no identifiers never touched the union-find. Every input entity must appear in the output. |
| Ran out of time on one problem | The time box failed. Next time, set an actual alarm and move on when it rings. |
Solved everything with time to spare? Redo the hardest one in the other language: E in Python
(defaultdict(set) of months per customer) or F in SQL (recursive CTE over an edge table). Translating between
SQL and Python thinking is exactly what a data engineer does all day.