#2525
Categorize Box According to Criteria
pupil · 510 · lc easy +27 · verified · 38.7% accepted · 238 likes · top 18%
Description
Given a box with dimensions length, width, height and mass, classify it as follows: it is "Bulky" if any dimension ≥ 104 or its volume ≥ 109; it is "Heavy" if mass ≥ 100. Return "Both" if both apply, "Neither" if neither does, or the applicable single label otherwise.
Example 1:
Input: length = 1000, width = 35, height = 700, mass = 300
Output: "Heavy"
Explanation:
None of the dimensions of the box is greater or equal to 104.
Its volume = 24500000 <= 109. So it cannot be categorized as "Bulky".
However mass >= 100, so the box is "Heavy".
Since the box is not "Bulky" but "Heavy", we return "Heavy".
Example 2:
Input: length = 200, width = 50, height = 800, mass = 50
Output: "Neither"
Explanation:
None of the dimensions of the box is greater or equal to 104.
Its volume = 8 * 106 <= 109. So it cannot be categorized as "Bulky".
Its mass is also less than 100, so it cannot be categorized as "Heavy" either.
Since its neither of the two above categories, we return "Neither".
Code
1
2
3