Problem Statement
You are to write permit-validation software for a parking lot that operates without human attendants. Before an automobile enters the lot, it must pull up to a permit dispenser. Here, the driver uses a credit card to purchase a fixed amount of parking time, after which she may proceed into the lot. Later in the day, when the driver retrieves her car and is on the way out, she must pause at a barrier to swipe her credit card. If she has exceeded her prepaid parking time, a surcharge is calculated and applied to her credit card. Drivers have a strong incentive to leave on time, since the prepaid parking rate is $1.00 an hour, but the surcharge rate is $0.10 a minute.
You are given a String[] named permitPurchases, each element of which describes one parking permit in the following format.
<TIME_ISSUED> <MINUTES_PURCHASED>
The <TIME_ISSUED> field is given in the format
<HOUR>.<MINUTE>
where <HOUR> is a non-zero-padded integer between 0 and 23, inclusive, and <MINUTE> is a two-digit, zero-padded integer between 00 and 59, inclusive.
The <MINUTES_PURCHASED> field of the permit description is a non-zero-padded integer between 15 and 1440, inclusive, indicating the number of parking minutes purchased for the car. Since parking time is purchased in quarter-hour increments, this number must be divisible by 15. There are no spaces in the permit description except for a single space separating the <TIME_ISSUED> and <MINUTES_PURCHASED> fields.
You are also given a String[] named exitStamps, each element of which represents the time at which the corresponding automobile exited. In other words, the kth element of exitStamps contains the exit time of the car whose permit is described by the kth element of permitPurchases. Each element of exitStamps is given in the same format as the <TIME_ISSUED> field defined above.
Each car arrives and departs between the times 0.00 and 23.59, inclusive. The time at which a car departs cannot be earlier than the time at which it arrived. Given that a driver is charged $0.10 for each minute in excess of her prepaid parking time, calculate the surcharge for each car and round it up. To be precise, you must replace the surcharge with the smallest whole-dollar amount that is no smaller than the surcharge. If a car has left within its prepaid parking time, the surcharge is 0. Return all surcharges in a int[], the kth element of which corresponds to the kth parking permit.
Definition
- Class:
- SwiftPark
- Method:
- computeSurcharges
- Parameters:
- String[], String[]
- Returns:
- int[]
- Method signature:
- int[] computeSurcharges(String[] permitPurchases, String[] exitStamps)
- (be sure your method is public)
Constraints
- permitPurchases contains between 1 and 50 elements, inclusive
- exitStamps contains the same number of elements as permitPurchases
- each element of permitPurchases adheres to the format described above
- each element of exitStamps adheres to the format described above
Examples
{"11.50 120", "11.30 120"}{"13.50", "13.50"}Returns: { 0, 2 }One driver enters at 11.50 and pays for 120 minutes, or 2 hours, of parking time. Exactly 2 hours later, he departs without a surcharge. Another driver enters at 11.30 and pays for 120 minutes as well, but he leaves 140 minutes later. This is 20 minutes over his prepaid time, so he incurs a surcharge of 20*$0.10 = $2.00. The smallest whole-dollar value that is no smaller than $2.00 is $2.{"9.45 15", "9.45 15"}{"9.45", "21.45"}Returns: { 0, 71 }One driver enters, pays for 15 minutes, and immediately departs. Another driver enters and stays for 12 hours or 720 minutes, of which she has paid for only 15 minutes, so she must pay for the additional 705. $70.50 rounds up to $71.{"9.17 225", "9.17 345"}{"15.02", "15.02"}Returns: { 12, 0 }Two drivers enter at 9.17 and leave at 15.02. One paid for 120 minutes fewer than he ended up staying. The other paid for the entire length of his stay.{"0.00 1425", "11.44 15"}{"23.55", "12.00"}Returns: { 1, 1 }One driver overstays her permit by 10 minutes, the other by 1 minute.{"3.27 900", "2.01 165", "15.30 285", "14.10 15", "4.50 60", "0.02 1140", "10.12 165", "6.57 45"}{"23.18", "12.14", "20.04", "14.19", "15.29", "11.11", "16.19", "23.05"}Returns: { 30, 45, 0, 0, 58, 0, 21, 93 }