Categorize Box According to Criteria
What is this problem about?
The "Categorize Box According to Criteria interview question" is a classification task based on dimensions and weight. You are given the length, width, height, and mass of a box. You must categorize it as "Bulky", "Heavy", "Both", or "Neither" based on specific numerical thresholds. A box is "Bulky" if any dimension is ≥104 or its volume is ≥109. It is "Heavy" if its mass is ≥100.
Why is this asked in interviews?
Companies like Microsoft and Zendesk use the "Categorize Box According to Criteria coding problem" to assess a candidate's ability to implement simple conditional logic and handle large numeric values (potential integer overflows). It tests basic clean coding practices and the ability to translate a set of requirements into a robust set of if-else statements.
Algorithmic pattern used
This problem follows the Math interview pattern using basic arithmetic and Conditional Logic.
- Bulky Check: Calculate volume (lengthimeswidthimesheight) and compare against the threshold. Also, check each dimension individually.
- Heavy Check: Compare mass against the constant threshold.
- Classification: Combine the boolean results of the two checks to return the appropriate string label.
Example explanation
Suppose a box has dimensions 104,2,2 and mass 50.
- Bulky? Yes, because length is 104.
- Heavy? No, because mass (50) is less than 100.
Result: "Bulky".
If dimensions were 10,10,10 and mass 200:
- Bulky? No (volume is 1000, all dimensions <104).
- Heavy? Yes (200≥100).
Result: "Heavy".
Common mistakes candidates make
- Integer Overflow: Using 32-bit integers to store the volume calculation (104imes104imes104=1012), which exceeds the capacity of standard integers. Use 64-bit types (long/long long).
- Redundant Conditions: Writing overlapping or messy
if conditions that make the code hard to read.
- Incorrect Thresholds: Confusing "strictly greater than" with "greater than or equal to".
Interview preparation tip
Always check the constraints on input variables. In this "Math interview pattern" problem, the volume calculation is the primary trap. In languages like Java or C++, ensure you cast to a 64-bit integer before multiplying.