Box nesting 2026-10-24
Represent a -dimensional box by its side-length vector and allow axis permutations. A box fits another when its permuted dimensions are all strictly smaller. Sorting each vector reduces containment to coordinatewise strict comparison, by the sorted-coordinate criterion for box containment. For an input-order-preserving subsequence, the longest chain ending at position has one plus the greatest chain length at an earlier fitting position. This last-box decomposition proves the dynamic programming recurrence. Sorting all dimensions and testing all ordered index pairs takes running time. Arbitrary reordering is a different convention, handled by the containment Directed acyclic graph.
Sort the two dimension vectors separately into ascending order, and . Then return true exactly when for every . Sorting costs and the coordinate comparisons cost .
Sufficiency follows by matching corresponding ranks and translating that rank matching back to the original axes. For necessity, suppose for some . The dimensions must all be assigned to strictly larger target dimensions. None of the first sorted target dimensions is large enough, leaving at most eligible slots. The pigeonhole principle gives a contradiction. This proves the sorted-coordinate criterion for box containment, including ties: equality fails the required strict fit.