Contest format & strategy
Quera uses an automatic judge. Knowing how each question type is graded is worth easy points.
Question types you will probably see on Quera
| Type | What you submit | How it's judged | Typical 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 query | A .sql file or query text | Run on hidden data (often MySQL, sometimes SQLite or PostgreSQL). Result set compared | Top-N per group, retention, dedup, running totals |
| Implement a function/class (file upload) | A .py file or zip from a template | Unit tests (pytest) call your functions | def transform(df) -> df, an ETL class, a validator |
| Output-only / dataset | A CSV or answer file you computed locally | Compared to the expected file, sometimes with a metric | "Clean this dataset and upload the result" |
| Short answer / MCQ | A value or option | Exact 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
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
- Restate the input β output in one sentence. Write down the edge cases you notice.
- Work one sample by hand, so you know what the expected output means.
- Code the simplest correct version, run it on the samples locally, then submit.
- 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."
| Phrase | What 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
| Verdict | Look at |
|---|---|
| Wrong Answer (samples pass) | Ties and ordering, empty input, duplicates, boundary wording ("more than" vs "at least"), rounding mode, output whitespace |
| Time Limit Exceeded | Per-line input()/print(), x in list inside a loop, nested loops over n β₯ 10β΄, repeated string concatenation, df.iterrows() |
| Runtime Error | Empty input (lines[0]), trailing blank line, int(''), recursion depth on deep input, missing import |
| Memory Limit | Loading the whole file as Python objects when a streaming pass would do; giant intermediate lists. Use generators and dicts keyed by id |
| Compilation / import error | Wrong 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).