Skip to main content
Back to problems
#2525
Easy Algorithms

Categorize box according to criteria

Math
38.7% acceptance
Feb 25, 2026
237
63
Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box. The box is "Bulky" if: Any of the dimensions of the box is greater or equal to 10^4. Or, the volume of the box is greater or equal to 10^9. If the mass of the box is greater or equal to 100, it is "Heavy". If the box is both "Bulky" and "Heavy", then its category is "Both". If the box is neither "Bulky" nor "Heavy", then its category is "Neither". If the box is "Bulky" but not "Heavy", then its category is "Bulky". If the box is "Heavy" but not "Bulky", then its category is "Heavy". Note that the volume of the box is the product of its length, width and height.

Solution

Rust
Time O(1)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn categorize_box(length: i32, width: i32, height: i32, mass: i32) -> String {
    let bulky = length >= 10_000
      || width >= 10_000
      || height >= 10_000
      || (length as i64 * width as i64 * height as i64 >= 1_000_000_000);
    let heavy = mass >= 100;
    match (bulky, heavy) {
      (true, true) => "Both".to_string(),
      (true, false) => "Bulky".to_string(),
      (false, true) => "Heavy".to_string(),
      (false, false) => "Neither".to_string(),
    }
  }
}