Check Store Open
Given the current hour (0-23), whether it is a weekend (true/false), and whether weekend hours are enabled (true/false), determine if the store is currently open. The store operates Monday-Friday from 8:00 to 18:00 (6 PM). On weekends, the store is only open if weekend hours are enabled. Return true if open, false otherwise.
For example, at hour 10 on a weekday, the store is open — return true. At hour 20 (8 PM) on any day, the store is closed — return false. At hour 14 on a Saturday with weekend hours enabled, return true. At hour 14 on a Sunday without weekend hours, return false.
This problem teaches compound boolean logic combining multiple conditions with AND and OR operators. Real-world business logic frequently combines time ranges, day-of-week rules, and special flags.
The solution first checks if the hour is within operating hours (8 to 17, since 18 is closing and means strictly before 18). If outside those hours, return false immediately. Then check the weekend rule: if it is a weekend and weekend hours are not enabled, return false. Otherwise, return true.
Edge cases include hour exactly 8 (open), hour exactly 18 (closed — closing time), invalid hours outside 0-23, and weekends where the weekend flag is true but weekend hours are disabled.
Example Input & Output
The opening hour itself still counts as open.
14 is inside the store's working hours.
20 is later than the closing time.
Algorithm Flow
Solution Approach
Check the operating hours first, then apply the weekend rule.
First check if the hour is outside the 8-to-18 operating window. If hour is before 8 or at/after 18, return false immediately. Then check the weekend condition: if it is a weekend day AND weekend hours are not enabled, return false. If both checks pass, the store is open — return true.
Time complexity is O(1), space complexity is O(1).
Best Answers
program check_store_open
dictionary
current_hour, open_hour, close_hour: integer
algorithm
input(current_hour, open_hour, close_hour)
if current_hour >= open_hour AND current_hour < close_hour then
output("OPEN")
else
output("CLOSED")
endif
endprogramComments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
