Problem · Database
Clean the Tape
Problem statement
The prices table contains a market-data tape for three assets. Return a cleaned tape with the columns row_index, timestamp, Asset_1, Asset_2, and Asset_3.
Cleaning rules
- Remove rows that are exact duplicates across
timestampand all three asset columns. - Sort the remaining rows by
timestampin ascending order. - Treat every asset value less than or equal to
0as missing. - For each asset independently, forward-fill a missing value from that asset's most recent positive value in the sorted tape.
- Never backfill. If an asset has no earlier positive value, keep the output value
NULL. - Reset the row index after sorting so that
row_indexis0,1, and so on.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
prices
Raw price-tape rows with timezone-neutral whole-second timestamps. Column order is timestamp, Asset_1, Asset_2, Asset_3.
| Column | Type | Nullable | Description |
|---|---|---|---|
| timestamp | Timestamp | No | Timezone-neutral observation time in whole-second YYYY-MM-DD HH:MM:SS precision. |
| Asset_1 | Decimal | Yes | Observed price for Asset_1. |
| Asset_2 | Decimal | Yes | Observed price for Asset_2. |
| Asset_3 | Decimal | Yes | Observed price for Asset_3. |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| row_index | Integer | No | Zero-based index after cleaning and sorting. |
| timestamp | Timestamp | No | — |
| Asset_1 | Decimal | Yes | — |
| Asset_2 | Decimal | Yes | — |
| Asset_3 | Decimal | Yes | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- The input contains at least
1row and at most2000rows. - Every timestamp is timezone-neutral and uses whole-second
YYYY-MM-DD HH:MM:SSprecision. - After exact duplicate rows are removed, no two remaining rows share the same
timestamp. - Each asset value is a decimal or
NULL. - An exact duplicate may occur more than once and must contribute only one output row.
- Return rows in ascending
timestamporder with the exact result-column order shown.