Compute Demurrage Charges From Tiered Terminal Free Time

Last updated: November 29, 2026

Quick Overview

Given the date a container was discharged at a port terminal, the date it was picked up, a number of free days, and a list of tiered daily rates, compute the demurrage fee owed. The last tier may be open ended.

Flexport
Coding & Algorithms
Software Engineer
Flexport
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given the date a container was discharged at a port terminal, the date it was picked up, a number of free days, and a list of tiered daily rates, compute the demurrage fee owed. The last tier may be open ended.

A warm-up in the style of a Flexport phone screen, built on a charge every importer dreads: demurrage after free time runs out at the terminal. The interviewer checks that you pin down day-counting conventions before coding and that tier arithmetic is clean and correct.

What the Interviewer Expects
  • Ask whether the discharge day counts as day one and whether weekends are excluded
  • Separate dwell days, free days and chargeable days explicitly
  • Walk tiers in order and handle an unbounded final tier
  • Return zero cleanly when pickup is inside free time
  • Test a case that spans every tier
Key Topics to Cover
Date Arithmetic
Tiered Pricing
Simulation
Edge Cases
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you exclude weekends and port holidays from free time?
  • Some carriers combine demurrage and detention into one clock. How would the model change?
  • How would you show the shipper a projected fee for each future pickup date?
Sharpen Your Skills on Codemia

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

Practice DSA Problems
Sample Answer
Requirements

Inputs: discharge and pickup dates, free_days (int), and tiers, a list of (length_in_days, daily_rate) where the last length may be None meaning unlimited. Convention to confirm: the disch...

High-Level Design

Compute dwell = (pickup - discharge).days + 1, then chargeable = max(0, dwell - free_days). Consume chargeable days tier by tier: take min(remaining, tier_length) days at that tier's rate, subtr...


Submit Your Answer
Markdown supported

Related Questions