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
Box Categorization ProblemInput BoxLength: 1000Width: 35Height: 700Mass: 300 kgVolume: 24.5MEvaluationBulky Check:Dims < 10⁴ ✗Vol < 10⁹ ✗Heavy Check:Mass ≥ 100 ✓ResultNot Bulky+ Heavy= "Heavy"Categories: "Neither", "Bulky", "Heavy", "Both"Bulky: Any dimension ≥ 10⁴ OR volume ≥ 10⁹Heavy: Mass ≥ 100
Understanding the Visualization
1
Input
Box with length=1000, width=35, height=700, mass=300
2
Evaluation
Check bulky and heavy conditions
3
Output
Return appropriate category string
Key Takeaway
🎯 Key Insight: Use boolean flags to separately track bulky and heavy conditions, then combine them with simple conditional 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