Code Logo

Check Parking Fee

Published at19 Apr 2026
Easy 0 views
Like0

This problem is based on a simple parking lot rule. The first two hours cost a flat price, and any extra hours after that add more to the bill.

In this version, parking costs 5 for up to 2 hours. After that, each extra hour adds 3 more.

For example, if a car stays for 4 hours, the total fee is 11. That is 5 for the first two hours, plus 6 for the next two hours.

So the task is to check the number of parking hours and calculate the final fee using those rules.

Example Input & Output

Example 1
Input
hours = 4
Output
11
Explanation

The first two hours cost 5, and the extra two hours add 6.

Example 2
Input
hours = 2
Output
5
Explanation

Exactly 2 hours still uses the base fee.

Example 3
Input
hours = 1
Output
5
Explanation

A short stay still uses the flat parking fee.

Algorithm Flow

Recommendation Algorithm Flow for Check Parking Fee
Recommendation Algorithm Flow for Check Parking Fee

Solution Approach

A good way to solve this is to separate the easy case from the extra-charge case.

If the parking time is 2 hours or less, the fee is always 5. That means you can return the base price right away.

If the parking time is more than 2 hours, you first figure out how many hours are extra.

The extra hour count is:

extra_hours <- hours - 2

Then you multiply that value by 3 and add it to the base fee of 5.

The full update becomes:

fee <- 5 + (extra_hours * 3)

So the logic is: small stay means flat price, longer stay means flat price plus extra hourly cost.

Best Answers

Solutions Coming Soon

Verified best solutions for this Challenge are still being analyzed and will be available soon.