Magicsheet logo

Categorize Box According to Criteria

Easy
100%
Updated 6/1/2025

Asked by 2 Companies

Topics

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\geq 10^4 or its volume is 109\geq 10^9. It is "Heavy" if its mass is 100\geq 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.

  1. Bulky Check: Calculate volume (lengthimeswidthimesheightlength imes width imes height) and compare against the threshold. Also, check each dimension individually.
  2. Heavy Check: Compare mass against the constant threshold.
  3. Classification: Combine the boolean results of the two checks to return the appropriate string label.

Example explanation

Suppose a box has dimensions 104,2,210^4, 2, 2 and mass 5050.

  • Bulky? Yes, because length is 10410^4.
  • Heavy? No, because mass (5050) is less than 100100. Result: "Bulky". If dimensions were 10,10,1010, 10, 10 and mass 200200:
  • Bulky? No (volume is 10001000, all dimensions <104< 10^4).
  • Heavy? Yes (200100200 \geq 100). Result: "Heavy".

Common mistakes candidates make

  • Integer Overflow: Using 32-bit integers to store the volume calculation (104imes104imes104=101210^4 imes 10^4 imes 10^4 = 10^{12}), 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.

Similar Questions