Algorithm for checking hour periods I have the following array that contains a day and the scheduled hours, i wanna know how to check if the given time falls in a period of that array, for example let's say the current time is 20:50 how to know if it's in that scheduled array?
{
   &quot;monday&quot;:[
      &quot;00:00&quot;, // Period number 1
      &quot;00:15&quot;,
      &quot;00:30&quot;,
      &quot;00:45&quot;,
      &quot;01:00&quot;,
      &quot;01:15&quot;,
      &quot;01:30&quot;,
      &quot;01:45&quot;,
      &quot;02:00&quot;,
      &quot;02:15&quot;,
      &quot;02:30&quot;,
      &quot;02:45&quot;,
      &quot;03:00&quot;,
      &quot;03:15&quot;,
      &quot;03:30&quot;,
      &quot;03:45&quot;,
      &quot;04:00&quot;,
      &quot;04:15&quot;,
      &quot;04:30&quot;,
      &quot;04:45&quot;,
      &quot;05:00&quot;,
      &quot;05:15&quot;,
      &quot;05:30&quot;,
      &quot;05:45&quot;,
      &quot;06:00&quot;,
      &quot;06:15&quot;,
      &quot;06:30&quot;,
      &quot;12:30&quot;, // Period number 2
      &quot;12:45&quot;,
      &quot;13:00&quot;,
      &quot;13:15&quot;,
      &quot;13:30&quot;,
      &quot;13:45&quot;,
      &quot;14:00&quot;,
      &quot;19:30&quot;, // Period number 3
      &quot;19:45&quot;,
      &quot;20:00&quot;,
      &quot;20:15&quot;,
      &quot;20:30&quot;,
      &quot;20:45&quot;,
      &quot;21:00&quot;,
      &quot;21:15&quot;,
      &quot;21:30&quot;,
      &quot;21:45&quot;,
      &quot;22:00&quot;,
      &quot;22:15&quot;,
      &quot;22:30&quot;,
      &quot;22:45&quot;,
      &quot;23:00&quot;,
      &quot;23:15&quot;,
      &quot;23:30&quot;,
      &quot;23:45&quot;
   ],
}
As @D.W. is suggesting, you can use the binary search technique which takes $O(\log n)$ time, where $n$ is the number of elements in the list.
Furthermore, if you want to know the corresponding period, there are many ways to it.
For example, You can make a separate array of periods and then perform a binary search on it.

Furthermore, you can improve the query time to $O(1)$ by maintaining an array of size 1440 = 24x60 as follows:
The $i^{th}$ entry of the array corresponds to the time $a:b$ where $a = i /60$ and $b = i \mod 60$. And, the value at $i^{th}$ entry is $1$ if time $a:b$ is in the list else it is $0$. Therefore, you can check in $O(1)$ time if an entry exist in the array.
To know the period in $O(1)$ time, you can maintain additional information in the array about the period in which the time lies. For example: an $i^{th}$ entry lies in $2^{nd}$ period. So basically it would be a two-dimensional array.