Categorize Box According to Criteria — LeetCode 2525 Python Solution
- Problem
- #2525
- Pattern
- Math and Number Theory
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box. The box is "Bulky" if: Any of the dimensions of the box is greater or equal to 104.
Example
- Input
- length = 1000, width = 35, height = 700, mass = 300
- Output
- "Heavy"
- Explanation
- None of the dimensions of the box is greater or equal to 104.
Python solution
class Solution:
def categorizeBox(self, length: int, width: int, height: int, mass: int) -> str:
v = length * width * height
bulky = int(any(x >= 10000 for x in (length, width, height)) or v >= 10**9)
heavy = int(mass >= 100)
i = heavy << 1 | bulky
d = ['Neither', 'Bulky', 'Heavy', 'Both']
return d[i]Complexity
| Measure | Complexity |
|---|---|
| Time | O(1) |
| Space | O(1) auxiliary |
Pattern: Math and Number Theory
Find the closed form, the invariant, or the modular identity — and skip the loop entirely. LeetCode 2525. Categorize Box According to Criteria is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Math.
The math and number theory guide has the Python template for the pattern and the 485 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 2525. Categorize Box According to Criteria?
- LeetCode 2525. Categorize Box According to Criteria is rated Easy on LeetCode.
- What is the time complexity of LeetCode 2525. Categorize Box According to Criteria?
- The Python solution on this page runs in O(1).
- What is the space complexity of LeetCode 2525. Categorize Box According to Criteria?
- The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 2525. Categorize Box According to Criteria cover?
- LeetCode 2525. Categorize Box According to Criteria is tagged Math on LeetCode.