Problem Description
Given four integers representing the dimensions (length, width, height) and mass of a box, determine its category based on specific criteria. The box is considered "Bulky" if any of its dimensions is at least 10^4 or if its volume (length * width * height) is at least 10^9. The box is considered "Heavy" if its mass is at least 100. Depending on whether one or both conditions are met, or neither, return "Both", "Heavy", "Bulky", or "Neither" respectively.
Key Insights
- Check if any of the dimensions is greater than or equal to 10,000.
- Calculate the volume and check if it is greater than or equal to 1,000,000,000.
- Use these checks to determine whether the box is "Bulky".
- Check if the mass is greater than or equal to 100 to determine if it's "Heavy".
- Combine the results of the two checks to decide the final category.
Space and Time Complexity
Time Complexity: O(1) – Only a fixed number of operations are performed. Space Complexity: O(1) – Only a constant amount of extra space is used.
Solution
We begin by checking if the box is considered "Bulky". This can be done by verifying if any dimension is at least 10,000 or if the computed volume (length multiplied by width multiplied by height) is at least 1,000,000,000. Next, we check if the box is "Heavy" by comparing its mass to 100. Finally, based on the outcomes of these checks, we return:
- "Both" if the box is both "Bulky" and "Heavy".
- "Heavy" if it's only heavy.
- "Bulky" if it's only bulky.
- "Neither" if it meets neither condition. The solution relies solely on simple conditional checks and arithmetic operations.