Building Boxes
Real-world version: Fewest Floor Crates in the Corner StackThe statement here is our own: the same inputs, outputs and technique.
Crates are stacked in the corner of a room, against two walls that meet at a right angle. A crate resting off the floor must be supported: each of the crates directly beneath it, the one behind it, and the one to its side, must be present.
More precisely, a crate at height h above the floor and not touching either wall needs the crate below it, the crate below and one step towards one wall, and the crate below and one step towards the other wall, all present.
A stack of n crates is built. Return the fewest crates that can be touching the floor.
Examples
Example 1
- Input
- n = 6
- Output
- 5
Three crates on the floor carry a fourth resting on them, and the two crates still to place each need a fresh floor crate beside them.
Example 2
- Input
- n = 5
- Output
- 4
Three crates on the floor carry a fourth, and the fifth needs one more floor crate to rest against.
Example 3
- Input
- n = 1
- Output
- 1
A single crate rests on the floor.
Constraints
- 1 <= n <= 10^9
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def fewest_floor_crates(n: int) -> int:public int fewestFloorCrates(int n)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Sell Diminishing-Valued Colored BallsReal-world version: Rare Poster RevenueMedium
- Minimum Number of Seconds to Make Mountain Height ZeroReal-world version: Clearing the Spoil Heap TogetherMedium
- Maximum Value at a Given Index in a Bounded ArrayReal-world version: The Tallest Post at a Chosen PlaceMedium
- Maximum Number of Groups With Increasing LengthReal-world version: How Many Growing Batches Can Be FilledHard