FastPrepQuery Weekly Store Opening Hours

Query Weekly Store Opening Hours

Apple logoApple● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

A store follows weekly opening intervals. Days are numbered 0 through 6 for Monday through Sunday. Each interval is [startDay, startHour, startMinute, endDay, endHour, endMinute] and is half-open: the store is open at its start and closed at its end.

An interval whose end occurs earlier in the week than its start wraps through Sunday into Monday. Intervals may overlap or touch. For every query [day, hour, minute], return whether the store is open at that weekly time.

Function

queryWeeklyStoreHours(openingHours: int[][], queries: int[][]) → boolean[]

Examples

Example 1

openingHours = [[0,8,0,0,10,0],[0,14,0,0,20,0]]queries = [[0,8,0],[0,12,0],[0,19,59],[0,20,0]]return = [true,false,true,false]

The store has two Monday phases. The half-open end at 20:00 is closed.

Example 2

openingHours = [[4,22,0,5,2,0],[6,22,0,0,2,0]]queries = [[5,1,30],[5,2,0],[6,23,0],[0,1,0],[0,2,0]]return = [true,false,true,true,false]

The first interval crosses Friday into Saturday. The second crosses the Sunday-to-Monday week boundary.

Constraints

  • 0 <= openingHours.length, queries.length <= 100000.
  • Days are in [0,6], hours in [0,23], and minutes in [0,59].
  • An interval's start and end weekly times are different.
  • The schedule repeats every week in one timezone.

More Apple problems

See Apple hiring insights
public boolean[] queryWeeklyStoreHours(int[][] openingHours, int[][] queries) {
    // Write your code here.
}
openingHours[[0,8,0,0,10,0],[0,14,0,0,20,0]]
queries[[0,8,0],[0,12,0],[0,19,59],[0,20,0]]
expected[true,false,true,false]
Checking account…