VOOZH about

URL: https://www.geeksforgeeks.org/dsa/count-intervals-that-intersects-with-a-given-meeting-time/

⇱ Count intervals that intersects with a given meeting time - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Count intervals that intersects with a given meeting time

Last Updated : 23 Jul, 2025

Given an array arr[][2] consisting of N pair of strings representing the starting and ending time (in 12 hours format) and a string P which represents the time of the meeting, the task is to find the count of intervals that contains the time P.

Examples:

Input: P = “12:01:AM”, arr[][2] = {{“12:00:AM”, “11:55:PM”}, {“12:01:AM”, “11:50:AM”}, {“12:30:AM”, “12:00:PM”}, {“11:57:AM”, “11:59:PM”}}
Output: 2
Explanation: The time P lies in the first and second time intervals.

Input: P = “12:01:AM”, arr[][2] = {{“09:57:AM”, “12:00:PM”} }
Output: 0
Explanation: No interval contains the time P.

Approach: The idea is to first convert all the times from 12-hour format into 24-hour format and then compare the range with Time P. Follow the steps below to solve the problem:

Below is the implementation of the above approach:


Output: 
2

 


Time Complexity: O(N)
Auxiliary Space: O(1)


 

Comment