CodeKitchen prep
0%
Contest in--:--:--
Start here Β· lesson 01/13

⏱️Contest format & strategy

⏳ ~10 min

Quera uses an automatic judge. Knowing how each question type is graded is worth easy points.

Question types you will probably see on Quera

TypeWhat you submitHow it's judgedTypical DE example
Programming (stdin β†’ stdout)A Python file (other languages are usually allowed too)Hidden test cases with a time and memory limit. Score per test (partial credit)Parse logs or CSV from stdin, aggregate, print a report
SQL queryA .sql file or query textRun on hidden data (often MySQL, sometimes SQLite or PostgreSQL). Result set comparedTop-N per group, retention, dedup, running totals
Implement a function/class (file upload)A .py file or zip from a templateUnit tests (pytest) call your functionsdef transform(df) -> df, an ETL class, a validator
Output-only / datasetA CSV or answer file you computed locallyCompared to the expected file, sometimes with a metric"Clean this dataset and upload the result"
Short answer / MCQA value or optionExact match"How many rows after the join?" / concept check

Read every problem statement for: exact output format, sort order and tie-breakers, rounding, NULL/empty handling, the DB engine/version (MySQL 8 vs SQLite changes date functions!), and the file/function names the template expects. Download any attached sample files and templates first.

Strategy for 6 problems / 150 minutes

0–8 min Skim all 6. Tag each as 🟒 quick / 🟑 doable / πŸ”΄ hard. Note the format details.
8–60 min Bank all 🟒 problems. Full points on easy ones beat partial points on hard ones.
60–130 min 🟑 then πŸ”΄, with a time box of ~25 min each. When stuck, submit a partial solution that passes the simple tests, then move on.
130–150 min Return to partial solutions: edge cases, performance, formatting. Never start something brand new in the last 10 minutes.

Partial scoring is your friend. On test-based judging, a brute-force solution that passes 60% of the tests is worth points. Submit it first, then optimise.

Where points are lost (and how to avoid it)

πŸ”’ Formatting

Extra spaces, a missing newline, 3.0 vs 3 vs 3.00, or True vs true. Copy the sample output format character by character.

↕️ Ordering

The statement says "order by X desc, then Y asc", so do exactly that. Sorting '10' < '9' as strings is a classic bug.

πŸ•³οΈ Empty / NULL

Empty input, a group with zero rows, NULL keys in joins, division by zero, missing JSON fields.

🐒 Performance

Hidden tests are bigger. Use O(n log n), avoid list.pop(0) and x in list inside loops, and read input in bulk.

🎯 Rounding

round(2.5) == 2 in Python. MySQL ROUND on exact DECIMALs rounds half away from zero (floats may differ). Integer division in SQL: 5/2 = 2 in SQLite and Postgres!

πŸ”€ Dialect

MySQL: DATE_FORMAT, DATEDIFF, backticks. SQLite: strftime, julianday. Postgres: date_trunc, :: casts.

Workflow per problem

  1. Restate the input β†’ output in one sentence. Write down the edge cases you notice.
  2. Work one sample by hand, so you know what the expected output means.
  3. Code the simplest correct version, run it on the samples locally, then submit.
  4. Harden it: build an empty-input test and a big generated input (a 10⁢-line file) and time it.
# quick local harness: run your script on sample files
#   python3 sol.py < sample1.in | diff - sample1.out && echo OK
# generate a big input to check speed:
import random
with open("big.in", "w") as f:
    n = 10**6
    f.write(f"{n}\n")
    f.write("\n".join(f"u{random.randint(1, 10**5)},{random.randint(-500, 5000)/100}" for _ in range(n)))

Prepare your environment now: a folder per problem, Python 3 with pandas, a terminal, and sqlite3 or a local MySQL/Docker to test queries. You can also paste queries into this app's SQL labs.

Reading a statement: an annotated example

Here is a made-up statement in the style you can expect. Every highlighted phrase is a hidden test waiting to happen.

"Given the rides table, report for each driver the number of completed rides and their average rating rounded to two decimals. Drivers with no completed rides must appear with 0 rides and a NULL rating. Sort by rides descending, then driver_id ascending. Output columns: driver_id, rides, avg_rating."

PhraseWhat it forces you to do
"completed rides"A filter, but put it in the ON clause of a LEFT JOIN, otherwise drivers with zero completed rides disappear
"average rating"Does a NULL rating count? AVG skips NULLs. Usually that's what's wanted; check the sample
"rounded to two decimals"ROUND(AVG(rating), 2) in the final SELECT only. Rounding earlier changes the result
"no completed rides … 0 rides and NULL rating"COUNT(r.id) (not COUNT(*), which gives 1) and leave AVG as NULL (no COALESCE)
"rides descending, then driver_id ascending"Both keys in ORDER BY. Without the tie-breaker the order is undefined and the judge may reject it
"Output columns: …"Exactly these three, in this order, with these names (some judges compare the header too)
SELECT d.id AS driver_id,
       COUNT(r.id)              AS rides,
       ROUND(AVG(r.rating), 2)  AS avg_rating
FROM drivers d
LEFT JOIN rides r ON r.driver_id = d.id AND r.status = 'completed'
GROUP BY d.id
ORDER BY rides DESC, driver_id ASC;

Triage when a submission fails

VerdictLook at
Wrong Answer (samples pass)Ties and ordering, empty input, duplicates, boundary wording ("more than" vs "at least"), rounding mode, output whitespace
Time Limit ExceededPer-line input()/print(), x in list inside a loop, nested loops over n β‰₯ 10⁴, repeated string concatenation, df.iterrows()
Runtime ErrorEmpty input (lines[0]), trailing blank line, int(''), recursion depth on deep input, missing import
Memory LimitLoading the whole file as Python objects when a streaming pass would do; giant intermediate lists. Use generators and dicts keyed by id
Compilation / import errorWrong file or function name, a library the judge doesn't have (pandas might not be installed for stdin problems: check!)

Remove debug prints before you submit. One stray line in stdout turns an accepted solution into Wrong Answer. Print debug output to sys.stderr instead: print(x, file=sys.stderr).

Quiz A SQL question says β€œorder by total desc”. You return the right rows in a different order. On an automated judge…
Quiz You have 150 minutes and 6 problems. Which strategy is best?
Quiz Your program passes every sample but gets Wrong Answer on 40% of the hidden tests (no time-outs). Most likely cause?
Quiz Ten minutes left. One problem is at 70% (partial), another is untouched. Best move?
🏁 --:--