Longest Cumulative Kitchen Delivery Time
Problem statement
The table delivery_access_log contains one day of keycard events for companies making deliveries to a kitchen.
Each row records a company_id, an event_timestamp_ns measured in nanoseconds since midnight, and an event_type equal to ENTER or EXIT.
For each company, calculate the total duration of all completed visits. Select the company with the greatest exact cumulative duration. Convert only that winning duration to minutes, round it down to an integer, and return exactly one row with these columns in order:
company_idduration_in_kitchen_minutes
If multiple companies have the same exact cumulative duration, return the one with the smaller company_id.
Table schema
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.
delivery_access_log
One day of kitchen access events for delivery companies.
| Column | Type | Nullable | Description |
|---|---|---|---|
| company_idPK | Integer | No | Delivery-company identifier. |
| event_timestamp_nsPK | Integer | No | Nanoseconds elapsed since midnight. |
| event_type | Text | No | ENTER or EXIT. |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| company_id | Integer | No | — |
| duration_in_kitchen_minutes | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
event_typeis exactlyENTERorEXIT.event_timestamp_nsis an integer from0through86399999999999.- Rows may appear in any physical order; events are ordered separately for each company by
event_timestamp_ns. - For this exercise, assume every company has at least one complete, non-overlapping visit and its events alternate
ENTERthenEXITwhen ordered byevent_timestamp_ns. - For this exercise, assume
event_timestamp_nsvalues are distinct within each company. - For this exercise, assume companies are ranked by their exact cumulative nanoseconds, and flooring is applied only to the winning company's returned minute value.
- For this exercise, assume equal exact cumulative durations are resolved by returning the smaller
company_id.