Class Solution
-
- All Implemented Interfaces:
public final class Solution1739 - Building Boxes.
Hard
You have a cubic storeroom where the width, length, and height of the room are all equal to
nunits. You are asked to placenboxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes:You can place the boxes anywhere on the floor.
If box
xis placed on top of the boxy, then each side of the four vertical sides of the boxymust either be adjacent to another box or to a wall.
Given an integer
n, return the minimum possible number of boxes touching the floor.Example 1:
Input: n = 3
Output: 3
Explanation: The figure above is for the placement of the three boxes. These boxes are placed in the corner of the room, where the corner is on the left side.
Example 2:
Input: n = 4
Output: 3
Explanation: The figure above is for the placement of the four boxes. These boxes are placed in the corner of the room, where the corner is on the left side.
Example 3:
Input: n = 10
Output: 6
Explanation: The figure above is for the placement of the ten boxes. These boxes are placed in the corner of the room, where the corner is on the back side.
Constraints:
<code>1 <= n <= 10<sup>9</sup></code>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classSolution.Companion
-
Field Summary
Fields Modifier and Type Field Description public final static Solution.CompanionCompanion
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerminimumBoxes(Integer n)-
-
Method Detail
-
minimumBoxes
final Integer minimumBoxes(Integer n)
-
-
-
-