Code Logo

Check Store Open

Published at19 Apr 2026
Logic & Conditionals Easy 6 views
Like0

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.

Learn about our pseudocode specification
Guide

Example Input & Output

Example 1
Input
current_hour = 9, open_hour = 9, close_hour = 18
Output
OPEN
Explanation

The opening hour itself still counts as open.

Example 2
Input
current_hour = 14, open_hour = 9, close_hour = 18
Output
OPEN
Explanation

14 is inside the store's working hours.

Example 3
Input
current_hour = 20, open_hour = 9, close_hour = 18
Output
CLOSED
Explanation

20 is later than the closing time.

Algorithm Flow

Recommendation Algorithm Flow for Check Store Open

Solution Approach

Check the operating hours first, then apply the weekend rule.

function isOpen(hour, isWeekend, weekendEnabled)
  if hour < 8 or hour >= 18 then return false
  if isWeekend and not weekendEnabled then return false
  return true

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

Pseudocode - Approach 1
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
endprogram