Check Whether a Business Is Open From Free-Text Hours

Last updated: November 29, 2026

Quick Overview

Parse an hours string such as "Mon-Fri 11:00-14:00, 17:00-22:00; Sat 10:00-02:00; Sun closed" and answer whether the business is open at a given day and time, correctly handling day ranges, split shifts, and hours that run past midnight.

Yelp
Coding & Algorithms
Software Engineer
Yelp
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


Parse an hours string such as "Mon-Fri 11:00-14:00, 17:00-22:00; Sat 10:00-02:00; Sun closed" and answer whether the business is open at a given day and time, correctly handling day ranges, split shifts, and hours that run past midnight.

Business owners enter hours into Yelp for Business in many shapes, and the Open Now badge must be right at 1 a.m. on a Saturday. The interviewer is checking careful parsing, a clean internal representation (minutes since Monday), and the overnight edge cases most candidates miss.

What the Interviewer Expects
  • Define the grammar before coding and ask about wrapping day ranges
  • Normalize to half open intervals in minutes of the week
  • Treat an end time at or before the start as closing the next day
  • Split intervals that wrap past Sunday midnight
  • Validate input and fail loudly on bad times
Key Topics to Cover
string parsing
intervals
time arithmetic
validation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you support holiday overrides like closed on Thanksgiving?
  • How would you compute closes in 30 minutes for the UI?
  • How do time zones and daylight saving time affect this?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Grammar: entries separated by ;. Each entry is a day spec (Mon, or a range like Mon-Fri, which may wrap as in Fri-Mon) followed by closed or comma separated HH:MM-HH:MM ranges. `00:00-00:0...

High-Level Design

Convert everything to minutes since Monday 00:00, a range of 0 to 10080. Each time range on each day becomes a half open interval. Overnight ranges add 1440 to the end. If the end passes 10080 (Sunday...


Submit Your Answer
Markdown supported

Related Questions