Leetcode 2525: Categorize Box According to Criteria

grid47
grid47
Exploring patterns and algorithms
Feb 28, 2024 6 min read

Given the dimensions and mass of a box, categorize it based on the following conditions: If any dimension is >= 10,000 or the volume is >= 1,000,000,000, the box is ‘Bulky’. If the mass is >= 100, the box is ‘Heavy’. The box can be categorized as ‘Both’, ‘Heavy’, ‘Bulky’, ‘Neither’, or a combination of the categories.
Problem
Approach
Steps
Complexity
Input: The input consists of four integers: `length`, `width`, `height`, and `mass`, representing the dimensions and mass of the box.
Example: length = 1200, width = 150, height = 800, mass = 150
Constraints:
• 1 <= length, width, height <= 100,000
• 1 <= mass <= 1,000
Output: Return a string representing the category of the box: 'Bulky', 'Heavy', 'Both', 'Neither', or a combination of these.
Example: Output: 'Heavy'
Constraints:
• The output is a string representing the box's category.
Goal: Determine the category of the box based on the provided dimensions and mass.
Steps:
• Calculate the volume of the box by multiplying `length * width * height`.
• Check if the box satisfies the 'Bulky' condition (any dimension >= 10,000 or volume >= 1,000,000,000).
• Check if the box satisfies the 'Heavy' condition (mass >= 100).
• Return the appropriate category based on the conditions.
Goal: The dimensions and mass are constrained as specified.
Steps:
• 1 <= length, width, height <= 100,000
• 1 <= mass <= 1,000
Assumptions:
• The input values are within the given constraints.
Input: length = 1200, width = 150, height = 800, mass = 150
Explanation: The box has mass >= 100, so it is categorized as 'Heavy'.

Input: length = 900, width = 900, height = 300, mass = 20
Explanation: The box does not satisfy either 'Bulky' or 'Heavy', so it is categorized as 'Neither'.

Input: length = 10000, width = 10000, height = 10000, mass = 50
Explanation: The box is 'Bulky' due to the large dimensions, but not 'Heavy' due to its mass.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus