Split a Loading Sequence So Each Item Type Ships Once

Last updated: November 29, 2026

Quick Overview

Items wait in a fixed loading order, labeled by type letter. Split the sequence into as many consecutive truckloads as possible so that every item type appears in exactly one truckload, and return the sizes of the truckloads.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


Items wait in a fixed loading order, labeled by type letter. Split the sequence into as many consecutive truckloads as possible so that every item type appears in exactly one truckload, and return the sizes of the truckloads.

A greedy interval problem in the style of Amazon assessments, set at a cross-dock where each SKU family must ship together. Graders check that you precompute last occurrences and close a partition exactly when the scan reaches the furthest last occurrence seen so far.

What the Interviewer Expects
  • Record the last index of every type
  • Scan while tracking the furthest last index in the current load
  • Close the load when the scan index equals that furthest index
  • Argue why closing as early as possible maximizes the number of loads
  • Return sizes in order
Key Topics to Cover
Greedy
Intervals
Hash Map
Two Pointers
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
  • What if each truckload also has a maximum size?
  • How would you do it in one pass without precomputing last positions?
  • What if the labels were arbitrary SKU strings instead of letters?
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

Input is a non-empty string of labels (any hashable characters). Output is a list of positive ints summing to the input length....

High-Level Design

Each type defines an interval from its first to last occurrence, and a valid split point must not cut any interval. Scanning left to right, maintain end = max(end, last[ch]). When i == end, no typ...


Submit Your Answer
Markdown supported