Leetcode 2525. Categorize Box According to Criteria
You are given the dimensions of a box (length, width, height) and the weight of the box. The box needs to be categorized based on the following criteria:
10^4
units or its volume is greater than or equal to 10^9
cubic units.100
units.Your task is to write a function that takes the dimensions and weight of the box and returns the appropriate category.
length * width * height
.>= 10^4
or if the volume of the box >= 10^9
.>= 100
.public class BoxCategorizer {
public String categorizeBox(int length, int width, int height, int weight) {
boolean isBulky = length >= 10000 || width >= 10000 || height >= 10000 || ((long)length * width * height >= 1000000000);
boolean isHeavy = weight >= 100;
if (isBulky && isHeavy) {
return "Both";
} else if (isBulky) {
return "Bulky";
} else if (isHeavy) {
return "Heavy";
} else {
return "Neither";
}
}
public static void main(String[] args) {
BoxCategorizer bc = new BoxCategorizer();
System.out.println(bc.categorizeBox(10000, 5000, 2000, 30)); // Output: Bulky
System.out.println(bc.categorizeBox(5000, 5000, 1000, 120)); // Output: Heavy
System.out.println(bc.categorizeBox(10000, 5000, 2000, 120)); // Output: Both
System.out.println(bc.categorizeBox(5, 5, 5, 5)); // Output: Neither
}
}
This simple and efficient approach fulfills the requirements of categorizing the box based on the given criteria.
Got blindsided by a question you didn’t expect?
Spend too much time studying?
Or simply don’t have the time to go over all 3000 questions?