Categorize Box According to Criteria

Let’s write a function to categorize the box based on the given conditions. Here’s the plan:

  1. Calculate the volume of the box: Multiply the length, width, and height.
  2. Check if the box is bulky: The box is bulky if any dimension is greater than or equal to ( 10^4 ), or if the volume is greater than or equal to ( 10^9 ).
  3. Check if the box is heavy: The box is heavy if the mass is greater than or equal to 100.
  4. Return the category based on the conditions.

Python solution:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class Solution:
    def categorizeBox(self, length: int, width: int, height: int, mass: int) -> str:
        # Calculate the volume
        volume = length * width * height

        # Check if the box is bulky
        is_bulky = length >= 10**4 or width >= 10**4 or height >= 10**4 or volume >= 10**9

        # Check if the box is heavy
        is_heavy = mass >= 100

        # Return the category based on the above checks
        if is_bulky and is_heavy:
            return "Both"
        elif is_bulky:
            return "Bulky"
        elif is_heavy:
            return "Heavy"
        else:
            return "Neither"

This code performs simple arithmetic operations and comparisons, so the time complexity is ( O(1) ), and the space complexity is also ( O(1) ).