Categorize Box According to Criteria - Problem
Imagine you work at a shipping company and need to categorize packages for proper handling and shipping costs. Given the dimensions (length, width, height) and mass of a box, you must determine its category based on specific criteria.
A box can be classified as:
- "Bulky" if any dimension ≥ 104 units OR volume ≥ 109 cubic units
- "Heavy" if mass ≥ 100 units
Based on these properties, return the appropriate category:
"Both"- if the box is both Bulky and Heavy"Bulky"- if the box is Bulky but not Heavy"Heavy"- if the box is Heavy but not Bulky"Neither"- if the box is neither Bulky nor Heavy
Note: Volume = length × width × height
Input & Output
example_1.py — Standard Case
$
Input:
length = 1000, width = 35, height = 700, mass = 300
›
Output:
"Heavy"
💡 Note:
The box is not bulky (no dimension >= 10^4 and volume = 24,500,000 < 10^9) but is heavy (mass = 300 >= 100), so it's categorized as "Heavy".
example_2.py — Both Bulky and Heavy
$
Input:
length = 200, width = 50, height = 800, mass = 50
›
Output:
"Neither"
💡 Note:
The box is not bulky (no dimension >= 10^4 and volume = 8,000,000 < 10^9) and not heavy (mass = 50 < 100), so it's "Neither".
example_3.py — Large Dimension
$
Input:
length = 10000, width = 1, height = 1, mass = 1
›
Output:
"Bulky"
💡 Note:
The box is bulky (length = 10^4 meets the dimension criteria) but not heavy (mass = 1 < 100), so it's "Bulky".
Constraints
- 1 ≤ length, width, height ≤ 105
- 1 ≤ mass ≤ 103
- Watch out for integer overflow when calculating volume
Visualization
Tap to expand
Understanding the Visualization
1
Measure Dimensions
Check if any dimension >= 10,000 units (like checking if box fits standard conveyor)
2
Calculate Volume
If dimensions OK, calculate total volume to see if >= 1 billion cubic units
3
Determine Bulky Status
Box is bulky if either dimension or volume criteria met
4
Check Weight
Weigh the package - heavy if >= 100 units
5
Assign Category
Combine bulky and heavy flags to determine final handling category
Key Takeaway
🎯 Key Insight: Evaluate bulky and heavy criteria independently using boolean flags, then combine with simple conditional logic for clean, maintainable code.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code