[LeetCode] Categorize Box According to Criteria

2525. Categorize Box According to Criteria

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 104.
    • Or, the volume of the box is greater or equal to 109.
  • 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.

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
string categorizeBox(int length, int width, int height, int mass) {
bool bulky = false;
if(length >= 1e4 or width >= 1e4 or height >= 1e4 or mass >= 1e4) bulky = true;
if(1ll * length * width * height >= 1e9) bulky = true;
bool heavy = mass >= 100;
if(bulky and heavy) return "Both";
if(!bulky and !heavy) return "Neither";
return bulky ? "Bulky" : "Heavy";
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2024/02/10/PS/LeetCode/categorize-box-according-to-criteria/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.