Skip to content

2933. High-Access Employees 👍

  • Time: $O(|\texttt{sort}|)$
  • Space: $O(n)$
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
 public:
  vector<string> findHighAccessEmployees(vector<vector<string>>& access_times) {
    unordered_set<string> ans;

    ranges::sort(access_times);

    for (int i = 0; i + 2 < access_times.size(); ++i) {
      const string& name = access_times[i][0];
      if (ans.contains(name))
        continue;
      if (name != access_times[i + 2][0])
        continue;
      if (stoi(access_times[i + 2][1]) - stoi(access_times[i][1]) < 100)
        ans.insert(name);
    }

    return {ans.begin(), ans.end()};
  }
};
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
  public List<String> findHighAccessEmployees(List<List<String>> access_times) {
    Set<String> ans = new HashSet<>();

    Collections.sort(access_times,
                     (a, b)
                         -> a.get(0).equals(b.get(0)) ? a.get(1).compareTo(b.get(1))
                                                      : a.get(0).compareTo(b.get(0)));

    for (int i = 0; i + 2 < access_times.size(); ++i) {
      String name = access_times.get(i).get(0);
      if (ans.contains(name))
        continue;
      if (!name.equals(access_times.get(i + 2).get(0)))
        continue;
      if (Integer.parseInt(access_times.get(i + 2).get(1)) -
              Integer.parseInt(access_times.get(i).get(1)) <
          100)
        ans.add(name);
    }

    return new ArrayList<>(ans);
  }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class Solution:
  def findHighAccessEmployees(self, access_times: list[list[str]]) -> list[str]:
    ans = set()

    access_times.sort()

    for i in range(len(access_times) - 2):
      name = access_times[i][0]
      if name in ans:
        continue
      if name != access_times[i + 2][0]:
        continue
      if int(access_times[i + 2][1]) - int(access_times[i][1]) < 100:
        ans.add(name)

    return list(ans)