Skip to content

2525. Categorize Box According to Criteria

  • Time: $O(1)$
  • Space: $O(1)$
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class Solution {
 public:
  string categorizeBox(int length, int width, int height, int mass) {
    const bool isBulky =
        length >= 10000 || width >= 10000 || height >= 10000 ||
        static_cast<long>(length) * width * height >= 1'000'000'000;
    const bool isHeavy = mass >= 100;
    if (isBulky && isHeavy)
      return "Both";
    if (isBulky)
      return "Bulky";
    if (isHeavy)
      return "Heavy";
    return "Neither";
  }
};
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
class Solution {
  public String categorizeBox(int length, int width, int height, int mass) {
    final boolean isBulky = length >= 10000 || width >= 10000 || height >= 10000 ||
                            (long) length * width * height >= 1_000_000_000;
    final boolean isHeavy = mass >= 100;
    if (isBulky && isHeavy)
      return "Both";
    if (isBulky)
      return "Bulky";
    if (isHeavy)
      return "Heavy";
    return "Neither";
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class Solution:
  def categorizeBox(self, length: int, width: int, height: int, mass: int) -> str:
    isBulky = length >= 10000 or width >= 10000 or height >= 10000 or length * \
        width * height >= 1_000_000_000
    isHeavy = mass >= 100
    if isBulky and isHeavy:
      return 'Both'
    if isBulky:
      return 'Bulky'
    if isHeavy:
      return 'Heavy'
    return 'Neither'