1739. Building Boxes Hard

@problem@discussion
#Math#Binary Search#Greedy



1/**
2 * [1739] Building Boxes
3 *
4 * You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes:
5 * 
6 * 	You can place the boxes anywhere on the floor.
7 * 	If box x is placed on top of the box y, then each side of the four vertical sides of the box y must either be adjacent to another box or to a wall.
8 * 
9 * Given an integer n, return the minimum possible number of boxes touching the floor.
10 *  
11 * Example 1:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/04/3-boxes.png" style="width: 135px; height: 143px;" />
13 * 
14 * Input: n = 3
15 * Output: 3
16 * Explanation: The figure above is for the placement of the three boxes.
17 * These boxes are placed in the corner of the room, where the corner is on the left side.
18 * 
19 * Example 2:
20 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/04/4-boxes.png" style="width: 135px; height: 179px;" />
21 * 
22 * Input: n = 4
23 * Output: 3
24 * Explanation: The figure above is for the placement of the four boxes.
25 * These boxes are placed in the corner of the room, where the corner is on the left side.
26 * 
27 * Example 3:
28 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/04/10-boxes.png" style="width: 271px; height: 257px;" />
29 * 
30 * Input: n = 10
31 * Output: 6
32 * Explanation: The figure above is for the placement of the ten boxes.
33 * These boxes are placed in the corner of the room, where the corner is on the back side.
34 *  
35 * Constraints:
36 * 
37 * 	1 <= n <= 10^9
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/building-boxes/
43// discuss: https://leetcode.com/problems/building-boxes/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn minimum_boxes(n: i32) -> i32 {
49        0
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_1739() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.