Skip to content

Practice Building Boxes

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1739
LeetCode Problem

Building Boxes

Problem Statement

Place n unit-cube boxes in a room of width, length and height n. A box can rest anywhere on the floor. To put a box on top of another box, all four vertical sides of the supporting box must be adjacent to a box or a wall. Return the smallest possible number of boxes touching the floor.

Source: Building Boxes on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 3
Output
3

# Example 2

Input
n = 4
Output
3

# Example 3

Input
n = 10
Output
6

Constraints

1 <= n <= 10^9

Related LeetCode Problems

Practice more problems similar to Building Boxes.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.