← Flexport Interview Insights

Flexport·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Flexport SWE interview with a shipping/logistics themed coding problem. Pretty domain-specific but the underlying logic is straightforward greedy stuff once you strip away the context.

Questions Asked (1)

Q1

Given a list of items each with a weight and a per-ship capacity C, write a function that loads items onto ships in order. If an item fits on the current ship without exceeding C, add it. If not, close that ship and start a new one. If a single item's weight exceeds C on its own, reject it entirely. Return the list of ships with their loaded item ids, and a separate list of rejected item ids. Must run in O(n).

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The domain wrapper threw me for a second.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then describe a single-pass greedy algorithm that maintains a current ship and a rejected list. Walk through the logic step-by-step, emphasizing O(n) time and O(1) extra space (excluding output), and discuss how to handle oversized items.

Pro tip: Explicitly state that you're treating the input as a stream and that the algorithm is online, which is crucial for logistics systems like Flexport's where items arrive sequentially and decisions must be made immediately.

1. Clarify requirements and edge cases

Ask about input format, whether item IDs are unique, if ships have a maximum item count, and how to handle empty input or items exactly equal to capacity. Confirm that order must be preserved and that rejected items are excluded from ships.

2. Outline the greedy single-pass algorithm

Explain that you'll iterate through items once, maintaining a current ship and its remaining capacity. For each item, if it fits, add it; if not, close the current ship, start a new one, and add the item if it fits; if the item alone exceeds capacity, reject it.

3. Walk through a concrete example

Use a small example (e.g., weights [2,3,4,5], C=5) to demonstrate how ships are formed and items rejected. Show the state of the current ship and rejected list at each step to validate the logic.

4. Analyze complexity and trade-offs

State that time complexity is O(n) because each item is processed once, and space complexity is O(n) for the output (or O(1) extra space if output is not counted). Discuss why a greedy approach is optimal here and mention that no backtracking is needed.

5. Discuss potential pitfalls and extensions

Mention edge cases like an item exactly equal to capacity, consecutive oversized items, or an empty input. Optionally, discuss how to handle multiple ships in parallel or if items could be reordered (which would change the problem).

Key Points to Mention

  • Single-pass O(n) time complexity with no nested loops
  • Greedy algorithm: always try to fit item on current ship before starting a new one
  • Handling oversized items by rejecting them immediately
  • Preserving input order and returning ships with item IDs
  • Space complexity: O(n) for output, O(1) auxiliary space
  • Edge cases: empty input, item weight exactly C, all items oversized

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.