Categorize Box According to Criteria - Problem

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.

Input & Output

Example 1 — Heavy Box
$ Input: length = 1000, width = 35, height = 700, mass = 300
Output: Heavy
💡 Note: Volume = 1000 × 35 × 700 = 24,500,000 < 10⁹, all dimensions < 10⁴, so not bulky. Mass = 300 ≥ 100, so heavy. Result: Heavy.
Example 2 — Bulky Box
$ Input: length = 200, width = 50, height = 800, mass = 50
Output: Neither
💡 Note: Volume = 200 × 50 × 800 = 8,000,000 < 10⁹, all dimensions < 10⁴, so not bulky. Mass = 50 < 100, so not heavy. Result: Neither.
Example 3 — Both Bulky and Heavy
$ Input: length = 10000, width = 20, height = 30, mass = 150
Output: Both
💡 Note: Length = 10000 ≥ 10⁴, so bulky. Mass = 150 ≥ 100, so heavy. Both conditions met. Result: Both.

Constraints

  • 1 ≤ length, width, height ≤ 105
  • 1 ≤ mass ≤ 103

Visualization

Tap to expand
Categorize Box According to Criteria INPUT length height width MASS length = 1000 width = 35 height = 700 mass = 300 ALGORITHM STEPS 1 Check Bulky (Dimension) Any dim >= 10000? 1000,35,700 all < 10000 [NO] 2 Check Bulky (Volume) Volume >= 10^9? 1000*35*700 = 24,500,000 < 1,000,000,000 [NO] 3 Check Heavy Mass >= 100? 300 >= 100 [YES - Heavy!] 4 Determine Category Bulky=false, Heavy=true NOT Both, NOT Neither NOT Bulky --> "Heavy" FINAL RESULT Bulky? NO Heavy? YES Output: "Heavy" Category Logic: Both = Bulky AND Heavy Neither = NOT Bulky AND NOT Heavy Heavy = Only Heavy is true Key Insight: Optimized Boolean Logic Use two boolean flags: isBulky (dimension >= 10^4 OR volume >= 10^9) and isHeavy (mass >= 100). Return "Both" if both true, "Neither" if both false, otherwise return the single true category. Time Complexity: O(1) | Space Complexity: O(1) - constant time boolean evaluation TutorialsPoint - Categorize Box According to Criteria | Optimized Boolean Logic
Asked in
Amazon 15 Google 12
18.5K Views
Medium Frequency
~5 min Avg. Time
842 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen