Design a Parking Lot Pricing System that calculates parking price efficiently using different pricing strategies.
The system supports exactly 3 pricing strategies.
Strategy values:
1 - Simple Hourly Pricing
2 - Fixed Time Block Pricing
3 - Slab Pricing
The date-time format is always: yyyy-MM-dd-HH-mm-day
where day is one of: mon, tue, wed, thu, fri, sat, sun.
Example date-time: 2026-04-14-08-10-tue
Use the provided day field directly to determine whether the timestamp is a weekday or weekend. You do not need to compute the day from the calendar date.
Both entryDateTime and exitDateTime are inclusive.
No partial pricing is allowed.
For strategies 1 and 3, if any part of an hour is touched, the full hour is charged.
For strategy 2, if any part of a block is touched, the full block is charged.
All prices are integers, and all calculated prices are returned as integers.
Pricing Strategies
Strategy 1 - Simple Hourly Pricing
Charge by touched hour. If the parking interval touches any minute inside an hour bucket, charge the full price for that hour bucket.
Each hour bucket is: HH:00 to HH:59
Day hours are: 09:00 to 16:59
Off hours are: 17:00 to 08:59
Rates:
Weekday day hour: 20
Weekday off hour: 10
Weekend day hour: 15
Weekend off hour: 12
Example: parking from 08:50 to 09:05 on a weekday touches two hour buckets, so it charges one weekday off hour and one weekday day hour.
Strategy 2 - Fixed Time Block Pricing
Charge by touched block instead of by duration. If the parking interval touches any minute inside a block, charge the full block price once for that date.
Weekday blocks:
00:00-08:59 = 60
09:00-12:59 = 70
13:00-17:59 = 110
18:00-23:59 = 140
Weekend blocks:
00:00-08:59 = 70
09:00-12:59 = 80
13:00-17:59 = 120
18:00-23:59 = 150
Example: parking for only 10 minutes inside a charged block still charges the full block price.
Strategy 3 - Slab Pricing
Charge by total touched hours using slabs.
Count how many hour buckets are touched by the full parking interval. Each hour bucket is: HH:00 to HH:59
Slabs:
First 2 touched hours: 30 per hour
Next 3 touched hours: 20 per hour
Beyond 5 touched hours: 10 per hour
This strategy depends only on the total number of touched hours. It does not depend on weekday, weekend, or hour of day.
Methods
ParkingLotPricingSystem()
- Creates a pricing system that uses the fixed strategy rules defined in this problem statement.
int calculatePrice(String entryDateTime, String exitDateTime, int strategy)
entryDateTime uses format yyyy-MM-dd-HH-mm-day
exitDateTime uses format yyyy-MM-dd-HH-mm-day
entryDateTime < exitDateTime
strategy is one of 1, 2, or 3
- Both entry time and exit time are inclusive.
- The interval may cross multiple hours and multiple dates.
- Returns the total parking price for the selected strategy.
String findMinimumPrice(String entryDateTime, String exitDateTime)
entryDateTime uses format yyyy-MM-dd-HH-mm-day
exitDateTime uses format yyyy-MM-dd-HH-mm-day
entryDateTime < exitDateTime
- Both entry time and exit time are inclusive.
- Computes the price using all
3 strategies and returns the cheapest result in format strategy-price.
- Example return value:
"1-200"
- If multiple strategies have the same minimum price, return the smaller strategy value.
Constraints
entryDateTime and exitDateTime are valid strings in format yyyy-MM-dd-HH-mm-day
day is always one of mon, tue, wed, thu, fri, sat, sun
entryDateTime < exitDateTime
- The parked duration is at most
1000000 minutes
- You must never use
null as a parameter value
Notes
- Use the supplied
day field directly. Do not recompute weekday or weekend from the date.
- For strategy
1, charge one full hourly price for every touched hour bucket.
- For strategy
2, charge one full block price for every touched block.
- For strategy
3, first count all touched hour buckets in the full interval, then apply the slab rates to that count.
- Because entry and exit are both inclusive, if the exit minute lies inside an hour bucket or block, that hour bucket or block is also charged.
- For strategy
2, if the stay spans multiple dates, evaluate touched blocks separately for each date.
- For
findMinimumPrice, compare the prices from strategies 1, 2, and 3, and return the cheapest one as strategy-price.
- If two or more strategies produce the same minimum price, choose the smaller strategy number.
Examples
Example 1
ParkingLotPricingSystem()
calculatePrice(entryDateTime = "2026-04-14-08-50-tue", exitDateTime = "2026-04-14-08-59-tue", strategy = 1)
Output: 10
Explanation:
The interval touches only one hour bucket: 08:00-08:59.
It is a weekday off hour, so the charge is 10.
Example 2
ParkingLotPricingSystem()
calculatePrice(entryDateTime = "2026-04-14-08-59-tue", exitDateTime = "2026-04-14-09-00-tue", strategy = 1)
Output: 30
Explanation:
Entry and exit are both inclusive.
The interval touches: 08:00-08:59 and 09:00-09:59.
08:00-08:59 is a weekday off hour, so it costs 10.
09:00-09:59 is a weekday day hour, so it costs 20.
Total = 10 + 20 = 30.
Example 3
ParkingLotPricingSystem()
calculatePrice(entryDateTime = "2026-04-18-18-10-sat", exitDateTime = "2026-04-18-18-19-sat", strategy = 2)
Output: 150
Explanation:
The interval touches only one weekend block: 18:00-23:59.
Even though the stay is only 10 minutes, the full block price is charged.
Example 4
ParkingLotPricingSystem()
calculatePrice(entryDateTime = "2026-04-14-08-10-tue", exitDateTime = "2026-04-14-14-30-tue", strategy = 3)
Output: 140
Explanation:
The interval touches these hour buckets: 08, 09, 10, 11, 12, 13, 14.
So the total touched hours count is 7.
First 2 hours: 2 * 30 = 60
Next 3 hours: 3 * 20 = 60
Remaining 2 hours: 2 * 10 = 20
Total = 60 + 60 + 20 = 140.
Example 5
ParkingLotPricingSystem()
findMinimumPrice(entryDateTime = "2026-04-14-08-50-tue", exitDateTime = "2026-04-14-08-59-tue")
Output: "1-10"
Explanation:
Strategy 1 touches one weekday off hour, so price = 10.
Strategy 2 touches weekday block 00:00-08:59, so price = 60.
Strategy 3 touches one hour bucket, so price = 30.
The minimum price is from strategy 1, so return "1-10".