Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
The team is about to commit to a delivery SLA and wants to see the shape of the tail before they pick a number. An average tells them nothing about the worst deliveries, which are the ones customers write in about.
Produce a small percentile table: one row each for p50, p75, p90 and p95, with the delivery time in minutes at that percentile across all cities. Order by label.
Result columns · in this order
label | The percentile: p50, p75, p90 or p95. |
minutes | Delivery time at that percentile, in whole minutes. Always a value some delivery recorded. |
How to approach it
Rank every delivery by time, then for each target percentile take the first row at or past its rank.
Sample input
| delivery_id | city | courier | minutes | delivered_on |
|---|---|---|---|---|
| 1 | Bengaluru | Asha | 18 | 2026-03-01 |
| 2 | Bengaluru | Asha | 22 | 2026-03-01 |
| 3 | Bengaluru | Rohit | 26 | 2026-03-02 |
| 4 | Bengaluru | Asha | 28 | 2026-03-02 |
| 5 | Bengaluru | Rohit | 30 | 2026-03-03 |
| 6 | Bengaluru | Meera | 30 | 2026-03-03 |
| 7 | Bengaluru | Meera | 34 | 2026-03-04 |
| 8 | Bengaluru | Rohit | 41 | 2026-03-04 |
| 9 | Bengaluru | Asha | 150 | 2026-03-05 |
| 10 | Pune | Kabir | 20 | 2026-03-01 |
| 11 | Pune | Kabir | 24 | 2026-03-01 |
| 12 | Pune | Nita | 26 | 2026-03-02 |
| 13 | Pune | Nita | 30 | 2026-03-02 |
| 14 | Pune | Kabir | 33 | 2026-03-03 |
| 15 | Pune | Nita | 36 | 2026-03-03 |
| 16 | Pune | Kabir | 45 | 2026-03-04 |
| 17 | Pune | Nita | 62 | 2026-03-05 |
| 18 | Pune | Kabir | 240 | 2026-03-05 |
| 19 | Chennai | Vikram | 19 | 2026-03-01 |
| 20 | Chennai | Priya | 23 | 2026-03-01 |
| 21 | Chennai | Vikram | 27 | 2026-03-02 |
| 22 | Chennai | Priya | 30 | 2026-03-03 |
| 23 | Chennai | Vikram | 38 | 2026-03-03 |
| 24 | Chennai | Priya | 52 | 2026-03-04 |
| 25 | Chennai | Vikram | 71 | 2026-03-04 |
| 26 | Chennai | Priya | 96 | 2026-03-05 |
26 rows — scroll inside the table to see them all.
Expected output
| label | minutes |
|---|---|
| p50 | 30 |
| p75 | 45 |
| p90 | 96 |
| p95 | 150 |
4 rows — all rows shown.
Constraints
ceil(n * XX / 100) once all deliveries are sorted by time. It always returns a time some delivery actually took.PERCENTILE_DISC. Build the rank arithmetic yourself, and note there is no CEIL for integers either — integer division truncates, so add 99 before dividing by 100 to round up.label.Worked example
There are 26 deliveries. For p90 the target rank is ceil(26 × 0.9) = ceil(23.4) = 24, so p90 is the 24th fastest delivery — 96 minutes.
In integer arithmetic, (26 * 90 + 99) / 100 = 2439 / 100 = 24, because the division truncates. Adding 99 first is how you round up without a CEIL function.
The punchline is the comparison: the mean delivery time is 48.1 minutes, which lands between p75 (45) and p90 (96). The average delivery is slower than three quarters of all deliveries.
What this tests
Whether you know what a percentile actually is, rather than which function name computes one — and whether you can express a ceiling in integer arithmetic.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.