![]() |
VOOZH | about |
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:
2
Time Complexity: O(N)
Auxiliary Space: O(1)