Skip to content
โ† Back to the archive

31 August 2026 ยท Advanced track

Closest Crate Match

Advanced Lists

Find the pair of shipping crates that adds up exactly to a target volume, preferring the most evenly matched pair.

You are given a list of container volumes at a shipping depot, sorted from smallest to largest, along with a target combined volume a customer has ordered. Find two different containers whose volumes add up exactly to the target. More than one pair can add up to the target. When that happens, choose the pair whose two volumes are closest to each other in size โ€” the depot prefers to keep the more balanced load. Return the matching pair as a tuple `(smaller, larger)`. If no two containers add up to the target, return `None`.

Constraints

  • volumes has at least 2 entries
  • All volumes are distinct positive integers
  • volumes is already sorted in increasing order
  • target is a positive integer
  • More than one pair may sum to target; return the pair with the smallest difference between its two volumes
  • If no pair sums to target, return None

Function signature

def closest_matched_crates(volumes, target):

Sign in to solve this bracket

Reading the problem is free for everyone. Opening the editor and solving it requires an account with Open Bracket+.