Ctrl K

Crates in a Warehouse Corner

Hard
A warehouse is a cube with side n. You need to place n identical unit-cube crates inside it. Crates can go anywhere on the floor. A crate may be put on top of another crate only if each of the four vertical sides of the lower crate is against a wall or another crate. Return the smallest possible number of crates standing on the floor.
Example 1
n=4 → 3

Put three crates in the corner in an L shape: the corner crate touches a wall on two sides and a neighbour on the other two. The fourth crate goes on top of it.

Example 2
n=11 → 7

A corner pyramid of 6 + 3 + 1 = 10 crates rests on 6 floor crates. One more crate needs a seventh crate on the floor.

Example 3
n=1 → 1
Constraints
  • 1 ≤ n ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsGrowing Groups Without Repeats HardPrices That Fade With Each Sale MediumEver-Growing Teams MediumShave Primes Into Order MediumLevel Out to a Palindrome Medium
loading Python…
Input
n=4
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 104 tests on the server, hidden ones included.