2
public List<String> alertNames(String[] keyName, String[] keyTime) {3
Map<String, PriorityQueue<Integer>> map = new HashMap<>();4
// for every entry in keyName and keyTime, add that time to a priorityqueue for that name5
for (int i = 0; i < keyName.length; i++) {6
PriorityQueue<Integer> pq = map.getOrDefault(keyName[i], new PriorityQueue<Integer>());7
// convert the time to an integer (0- 2359 inclusive) for easy comparisons9
Integer.parseInt(keyTime[i].substring(0, 2)) * 10010
+ Integer.parseInt(keyTime[i].substring(3)));11
map.put(keyName[i], pq);14
// Generate the "answer" list15
List<String> ans = new ArrayList<>();16
for (String s : map.keySet()) {17
// For each name in the map, determine if that name used the keycard within 1 hour18
PriorityQueue<Integer> pq = map.get(s);24
// Sort the names alphabetically25
Collections.sort(ans);29
// Greedy function to determine if there were 3 uses within an hour30
private boolean active(PriorityQueue<Integer> pq) {31
// If there are two or less entries, the user could not have entered 3 times, return false32
if (pq.size() < 3) return false;34
// Create rolling data35
// Using PriorityQueues, the lowest number is removed first by default40
// Test if two entrances are within 1 hour (100 in integer)41
if (c - a <= 100) return true;42
while (pq.size() > 0) {46
if (c - a <= 100) return true;49
// If the full Queue has been checked, return false