licensePlateis non-blank and unique.- Costs and kilometer values are non-negative integers.
yyyy-mm-dd (e.g., 2025-08-28).licensePlate (unique), costPerDay, freeKmsPerDay (free kilometers per day) and costPerKm for extra kilometers that you travel, beyond freeKmsPerDay . [fromDate..tillDate]. endDate. days = 1 + (effectiveEndDate - fromDate) in whole calendar days.
2025-08-28 → 2025-08-28 ⇒ 1 day2025-08-28 → 2025-08-30 ⇒ 3 dayseffectiveEndDate = max(tillDate (from booking), endDate (provided at endTrip))
licensePlate is non-blank and unique.orderId is non-blank and unique.carLicensePlate is non-blank and must refer to an existing car.yyyy-mm-dd, fromDate ≤ tillDate.[A..B] and [C..D] overlap if A ≤ D and C ≤ B.true if successfully booked and all rules pass; otherwise false.orderId refers to a previously booked order.odometerReading is the car’s current odometer at handover (positive integer).orderId, finalOdometerReading and endDate are valid.addCar("KA01AB1234", 1200, 100, 10)
bookCar("ORD-1", "KA01AB1234", "2025-08-28", "2025-08-30") // 3 days (28,29,30)
→ true
startTrip("ORD-1", 5000)
endTrip("ORD-1", 5250, "2025-08-29") // endDate earlier than tillDate → charge till 2025-08-30
days = 3
tripKms = 5250 - 5000 = 250
freeAllowance = 3 × 100 = 300
extraKms = max(0, 250 - 300) = 0
totalCost = (3 × 1200) + (0 × 10) = 3600
→ returns 3600
addCar("DL09CD4321", 1500, 120, 8)
bookCar("ORD-2", "DL09CD4321", "2025-09-01", "2025-09-02") // 2 days (1,2)
→ true
startTrip("ORD-2", 20000)
endTrip("ORD-2", 20550, "2025-09-04") // extended; effectiveEndDate = 2025-09-04
days = 1 + (2025-09-04 - 2025-09-01) = 4
tripKms = 20550 - 20000 = 550
freeAllowance = 4 × 120 = 480
extraKms = max(0, 550 - 480) = 70
totalCost = (4 × 1500) + (70 × 8) = 6000 + 560 = 6560
→ returns 6560
addCar("MH12EF9999", 1000, 80, 12)
bookCar("ORD-3", "MH12EF9999", "2025-08-10", "2025-08-12") // 10,11,12
→ true
bookCar("ORD-4", "MH12EF9999", "2025-08-12", "2025-08-15") // overlaps on 12 (inclusive)
→ false
null. Assume date strings are well-formed yyyy-mm-dd.finalOdometerReading < startOdometerReading) need not be handled, as inputs are stated valid.