Problem Statement
You have a stack of boxes you would like to ship internationally using your preferred shipping service. However, the service only allows international shipping of packages whose (length + girth) does not exceed thresholdSize inches. The length of a box is its longest side. The girth is the distance around the box perpendicular to the length. In other words, if the two non-length sides are called width and height, girth is defined as width + height + width + height. If a box has two equal sides that are greater than the third side, or if a box has three equal sides, any of the multiple longest sides can be used as the length.
Your boxes are given as a String[], dimensions, where each element represents a single box formatted as "<side>x<side>x<side>" (quotes for clarity only). Each <side> is a positive integer with no leading zeros. All lengths are given in inches. Return a int[] containing the zero-based indices of all the boxes that can be shipped, sorted in ascending order. If none of the boxes can be shipped, return an empty int[].
Definition
- Class:
- InternationalShipping
- Method:
- getShippable
- Parameters:
- String[], int
- Returns:
- int[]
- Method signature:
- int[] getShippable(String[] dimensions, int thresholdSize)
- (be sure your method is public)
Constraints
- dimensions will contain between 1 and 50 elements, inclusive.
- Each element of dimensions will be formatted as "<side>x<side>x<side>" (quotes for clarity only), where each <side> is an integer between 1 and 100, inclusive, with no leading zeros. Each 'x' is lowercase.
- thresholdSize will be between 20 and 300, inclusive.
Examples
{"10x4x5", "3x3x3", "1x21x1"}25
Returns: { 1, 2 }Box 0 has a length of 10 and a girth of 4 + 5 + 4 + 5 = 18. (10 + 18) is greater than 25, so the package cannot be shipped. Box 1 has a length of 3 and a girth of 12. (3 + 12) does not exceed 25, so this package can be shipped. Box 2 has a length of 21 and a girth of 4. (21 + 4) does not exceed 25, so this package can also be shipped. Since boxes 1 and 2 are shippable, the return value is {1, 2}.{"100x99x98", "99x98x100", "98x99x100", "99x100x98"}300
Returns: { }All of these boxes have the same dimensions, and none of them can be shipped internationally.{"1x1x1", "1x2x3", "4x8x12", "1x1x1"}50
Returns: { 0, 1, 2, 3 }All four boxes can be shipped.