Problem Statement
Calculate how much it would cost to ship a package from sourceZipCode to destZipCode. The shipping service uses the following formula to determine shipping cost: weight * rate * (zoneDifference + 1). You are given a String[], zones, which defines the locations of various zip codes. Each element of zones is a single space delimited list of five-digit integers. Element i (zero-indexed) of zones contains all the zip codes located in zone i. zoneDifference is defined as the absolute value of the difference between the zone of sourceZipCode and the zone of destZipCode.
Definition
- Class:
- ShippingFee
- Method:
- getFee
- Parameters:
- int, int, int, int, String[]
- Returns:
- int
- Method signature:
- int getFee(int weight, int rate, int sourceZipCode, int destZipCode, String[] zones)
- (be sure your method is public)
Constraints
- weight will be between 1 and 100, inclusive.
- rate will be between 1 and 10, inclusive.
- sourceZipCode and destZipCode will each be between 10000 and 99999, inclusive.
- zones will contain between 1 and 50 elements, inclusive.
- Each element of zones will contain between 5 and 47 characters, inclusive.
- Each element of zones will be a single space delimited list of one or more five-digit integers, with no leading or trailing spaces.
- zones will contain no duplicate integers.
- Both sourceZipCode and destZipCode will exist in zones.
Examples
50
2
48105
79915
{"94305", "79915 80201", "48105", "03122"}Returns: 200
In this example, a 50 pound package is sent from zip code 48105 to zip code 79915. 48105 is in element 2 of zones, so that means 48105 is located in zone 2. 79915 is located in zone 1. The difference in zones is 1, so the shipping cost is 50 * 2 * (1 + 1) = 200.1
10
94305
94305
{"94305 94309", "71203 65033 74390", "13820"}Returns: 10
The package is sent between two locations with the same zip code. The shipping cost is 1 * 10 * (0 + 1) = 10.5
1
25000
25001
{"90200 82922 73022", "25000 25001"}Returns: 5
The source and destination have different zip codes, but they're in the same zone.100
10
10000
99999
{"10000 20000", "30000 40000", "50000 60000", "70000 80000", "90000 99999", "33333"}Returns: 5000
The difference in zones between 10000 and 99999 is 4.