Find Containers Sitting at the Terminal Past Free Time

Last updated: November 29, 2026

Quick Overview

Given container event records and a shipments table, list every container that has been discharged at the destination terminal but not yet gated out, and has been there more than four days, with the shipper and terminal so operations can schedule pickups.

Flexport
Data Manipulation (SQL/Python)
Data Engineer
Flexport
November 29, 2026
Data Engineer
Phone Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given container event records and a shipments table, list every container that has been discharged at the destination terminal but not yet gated out, and has been there more than four days, with the shipper and terminal so operations can schedule pickups.

Containers that sit at the terminal past free time cost Flexport's customers demurrage, so ops teams work from a daily list of at-risk boxes. The interviewer checks anti-join technique, handling of duplicate events, and whether you think about what "today" means in a scheduled job.

What the Interviewer Expects
  • Use the earliest discharge event per container to handle duplicates
  • Find missing gate-out events with a LEFT JOIN or NOT EXISTS anti-join
  • Compute days at terminal against a clear reference date
  • Join to shipments for shipper and terminal
  • Order output so the most urgent containers come first
Key Topics to Cover
Anti-Join
LEFT JOIN
Deduplication
Date Arithmetic
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • Free time differs by terminal and carrier contract. How would you join that in?
  • How would you turn this into an incremental daily job instead of a full scan?
  • What if the gate-out event arrives two days late from the terminal feed?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

container_events(container_id, shipment_id, event_type, event_time) where event_type includes DISCHARGED and GATE_OUT; shipments(shipment_id, shipper_name, dest_terminal). Feeds can repeat e...

Approach
  1. Collapse discharge events to one row per container with MIN(event_time).
  2. Anti-join against gate-out events.
  3. Filter on dwell over 4 days.
  4. Join shipments, sort by dwell descending....

Submit Your Answer
Markdown supported

Related Questions