-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemployeePriority.txt
44 lines (36 loc) · 1.73 KB
/
employeePriority.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2933. High-Access Employees
You are given a 2D 0-indexed array of strings, access_times, with size n. For each i where 0 <= i <= n - 1,
access_times[i][0] represents the name of an employee, and access_times[i][1] represents the access time of that employee.
All entries in access_times are within the same day.
The access time is represented as four digits using a 24-hour time format, for example, "0800" or "2250".
An employee is said to be high-access if he has accessed the system three or more times within a one-hour period.
Times with exactly one hour of difference are not considered part of the same one-hour period. For example, "0815" and "0915" are not part of the same one-hour period.
Access times at the start and end of the day are not counted within the same one-hour period. For example, "0005" and "2350" are not part of the same one-hour period.
Return a list that contains the names of high-access employees with any order you want.
class Solution {
public:
vector<string> findHighAccessEmployees(vector<vector<string>>& access_times) {
unordered_map<string,vector<int>> m;
vector<string> ans;
for(auto &i:access_times)
{
int a=((i[1][0]-'0')*10+i[1][1]-'0')*60+((i[1][2]-'0')*10+i[1][3]-'0');
m[i[0]].push_back(a);
}
for(auto &i:m)
{
if(i.second.size()<3)
continue;
sort(i.second.begin(),i.second.end());
for(int j=0;j<i.second.size()-2;j++)
{
if(abs(i.second[j]-i.second[j+1])<60 && abs(i.second[j]-i.second[j+2])<60)
{
ans.push_back(i.first);
break;
}
}
}
return ans;
}
};