


The office doors can only be open by using the ‘key-cards’ given to the workers. Whenever a worker uses their ‘key-card’ to unlock the door, the office’s security system saves his name and the time when he used it in ‘any order’. The security system programmed in such a way that, if any worker uses the ‘key-card’ strictly “more than two times in one hour”, then the system emits an ‘alert’.
You are given two string arrays ‘keyName’, and ‘keyTime’, denoting the ‘name’ and the ‘time’ of the worker when he used his ‘key-card’ in a “single day”. Your task is to find the list of “unique worker” names who received an ‘alert’.
Note:
1. The ‘keyName’ contains only the lower-case English alphabets.
2. The ‘keyTime’ is given in the 24-hour format “HH:MM”, such as “00:00”, “13:35”, and “23:59” are some of the valid times.
3. “08:05 - 09:05” is considered to be within a ‘one-hour’, whereas “12:05 - 13:06” is not considered to be within a ‘one-hour’ period.
4. The system saves the ‘name’ and the ‘time’ of the workers in ‘any order’.
5. Each pair of [‘keyName’, ‘keyTime’] is ‘unique’.
6. Print the output in ‘increasing’ order alphabetically.
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then, the T test cases follow.
The first line of each test case contains a single positive integer, ‘N’, denoting the total number of workers in the office.
The second line of each test case contains ‘N’ space-separated string, ‘keyName[i]’, representing the ith worker’s name.
The third line of each test case contains ‘N’ space-separated string, ‘keyTime[i]’, representing the ith worker’s time.
Output Format:
For each test case, print a single line containing space-separated integers denoting elements of the list of the “unique worker” names sorted in “increasing order alphabetically”, as described in the problem statement.
The output for each test case will be printed in a separate line.
Note:
1. You do not need to print anything. It has already been taken care of. Just implement the given function.
2. If the list is ‘empty’, then you have to return an “empty list”.
1 <= ‘T’ <= 10
1 <= ‘N’ <= 10^4
1 <= ‘keyName[i].length’ <= 10
“00:00” <= ‘keyTime[i]’ <= “23:59”
keyName.length == keyTime.length == ‘N’
Where ‘T’ is the number of test cases, ‘N’ is the number of workers, ‘keyName[i]’ is the name of the ith worker, and ‘keyTime[i]’ is the time of the ith worker.
Time Limit: 1 sec.
1
5
ninja ninja kevin ninja kevin
09:00 09:30 10:10 09:59 10:00
ninja
“ninja” uses the ‘key-card’ more than two times in a one-hour period, i.e., at [“09:00”, “09:30”, “09:59”].
1
3
ninja ninja ninja
14:00 14:02 16:00
“ninja” did not use his ‘key-card’ more than two times in a one-hour. So, the output is the blank line.
Think of sorting based on keyName.
O(N * logN), where N is the number of workers.
We are storing the system’s data based on the worker’s ‘name’ and ‘time’, which will take O(N * logN). Hence, the time complexity will be O(N * logN).
O(N), where N is the number of workers.
As we are using an array to store the system’s data, that is the size of ‘N’. Hence, the space complexity will be O(N).