Load Crates Into a Row of Storage Bays

Asked at Pinterest · Coding Questions · Difficulty: Medium · Last asked Jun 5, 2026

A storage corridor is a row of bays numbered `0` to `n - 1` from the entrance, and each bay has a ceiling height. You have a pile of crates, each with a height, and you want to store as many of them as possible. Crates enter only through the entrance at bay `0` and slide inward, so a crate can never pass a bay whose ceiling is lower than the crate.

Loading the problem…