Classify a box as Bulky, Heavy, Both or Neither from its dimensions and mass

Quick Overview

Classify a box as Bulky, Heavy, Both or Neither from its three dimensions and its mass, using inclusive thresholds on side length, volume and weight. It tests careful reading of boundary conditions and avoiding integer overflow when the volume gets large.

Classify a box as Bulky, Heavy, Both or Neither from its dimensions and mass

Company: Zendesk

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given four integers `length`, `width`, `height` and `mass`, representing the dimensions and mass of a box, categorize the box according to the following criteria: - The box is "Bulky" if any of its dimensions is greater than or equal to ${10^4}$, or its volume (`length * width * height`) is greater than or equal to ${10^9}$. - The box is "Heavy" if its mass is greater than or equal to 100. - 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 only "Bulky" but not "Heavy", then its category is "Bulky". - If the box is only "Heavy" but not "Bulky", then its category is "Heavy". Return a string representing the category of the box. ### Function Signature ```python def categorize_box(length: int, width: int, height: int, mass: int) -> str: ``` ### Rules - The return value is exactly one of `"Both"`, `"Bulky"`, `"Heavy"` or `"Neither"`, spelled and capitalized as shown. - Both thresholds are inclusive: a side of exactly 10000, a volume of exactly 1000000000 or a mass of exactly 100 meets its condition. ### Constraints - `1 <= length, width, height <= 10^5` - `1 <= mass <= 10^3` ### Examples ```text Input: length = 1000, width = 35, height = 700, mass = 300 Output: "Heavy" ``` The volume is 1000 * 35 * 700 = 24,500,000, which is below ${10^9}$, and no side reaches ${10^4}$, so the box is not Bulky. The mass 300 is at least 100, so it is Heavy. ```text Input: length = 200, width = 50, height = 800, mass = 50 Output: "Neither" ``` The volume is 8,000,000 and no side reaches ${10^4}$, so the box is not Bulky. The mass 50 is below 100, so it is not Heavy either. ```text Input: length = 1000, width = 1000, height = 1000, mass = 100 Output: "Both" ``` No single side reaches ${10^4}$, but the volume is exactly ${10^9}$, so the box is Bulky. The mass is exactly 100, so it is also Heavy.

Overview: Classify a box as Bulky, Heavy, Both or Neither from its three dimensions and its mass, using inclusive thresholds on side length, volume and weight. It tests careful reading of boundary conditions and avoiding integer overflow when the volume gets large.

Zendesk logo
Zendesk
Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Given four integers length, width, height and mass, representing the dimensions and mass of a box, categorize the box according to the following criteria:

  • The box is "Bulky" if any of its dimensions is greater than or equal to 104{10^4} , or its volume ( length * width * height ) is greater than or equal to 109{10^9} .
  • The box is "Heavy" if its mass is greater than or equal to 100.
  • 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 only "Bulky" but not "Heavy", then its category is "Bulky".
  • If the box is only "Heavy" but not "Bulky", then its category is "Heavy".

Return a string representing the category of the box.

Function Signature

def categorize_box(length: int, width: int, height: int, mass: int) -> str:

Rules

  • The return value is exactly one of "Both" , "Bulky" , "Heavy" or "Neither" , spelled and capitalized as shown.
  • Both thresholds are inclusive: a side of exactly 10000, a volume of exactly 1000000000 or a mass of exactly 100 meets its condition.

Constraints

  • 1 <= length, width, height <= 10^5
  • 1 <= mass <= 10^3

Examples

Input: length = 1000, width = 35, height = 700, mass = 300
Output: "Heavy"

The volume is 1000 * 35 * 700 = 24,500,000, which is below 109{10^9}, and no side reaches 104{10^4}, so the box is not Bulky. The mass 300 is at least 100, so it is Heavy.

Input: length = 200, width = 50, height = 800, mass = 50
Output: "Neither"

The volume is 8,000,000 and no side reaches 104{10^4}, so the box is not Bulky. The mass 50 is below 100, so it is not Heavy either.

Input: length = 1000, width = 1000, height = 1000, mass = 100
Output: "Both"

No single side reaches 104{10^4}, but the volume is exactly 109{10^9}, so the box is Bulky. The mass is exactly 100, so it is also Heavy.