You are given a list of badge access log records. Each record is [name, time, action], where name identifies a person, time is a minute of the day written as a string (for example "100"), and action is "enter" or "exit". Find two groups of people:
-
People with mismatched access: they entered without a corresponding exit, or exited without a corresponding enter.
-
People who entered a room 3 or more times within any 1-hour window (60 minutes).
Return a list of two sorted lists. The first holds the names of people with mismatched access, and the second holds the names of people who entered 3 or more times within a 1-hour window.
Function Signature
def badge_access_logs(records: list[list[str]]) -> list[list[str]]:
Rules
-
Records can arrive in any order. Replay each person's records in increasing order of time, comparing times as integers. Records of the same person with the same time keep their input order.
-
Everyone starts outside. A person has mismatched access if, during that replay, they enter while already inside, exit while already outside, or are still inside after their last record.
-
Every
"enter"
record counts toward the frequent check, including an entry that is itself a mismatch. A person is frequent when three of their enter times
t1 <= t2 <= t3
satisfy
t3 - t1 <= 60
. The window is inclusive, so entries at minutes 0, 20 and 60 qualify.
-
Each name appears at most once in each list, and the same person can appear in both. Sort each list in ascending lexicographic order. Either list may be empty.
Constraints
-
1 <= len(records) <= 10^4
-
Each record is
[name, time, action]
.
-
name
consists of lowercase English letters.
-
0 <= int(time) <= 1440
-
action
is either
"enter"
or
"exit"
.
Examples
Input: records = [["alice","100","enter"],["bob","120","enter"],["alice","130","exit"],["bob","140","enter"],["alice","160","enter"],["alice","200","enter"],["bob","300","exit"]]
Output: [["alice","bob"],[]]
Alice enters at 160 and again at 200 without exiting in between, and she is still inside at the end. Bob enters at 120 and again at 140 without exiting; nobody is frequent, because Alice's three entries (100, 160, 200) span 100 minutes and Bob has only two.
Input: records = [["carl","10","enter"],["carl","30","exit"],["carl","50","enter"],["carl","60","enter"],["carl","70","enter"],["dave","5","exit"]]
Output: [["carl","dave"],["carl"]]
Carl enters at 60 and at 70 while already inside, and his entries at 50, 60 and 70 fall within 20 minutes. Dave exits at 5 without having entered.
Input: records = [["erin","60","enter"],["frank","5","enter"],["erin","0","enter"],["erin","70","exit"],["erin","10","exit"],["frank","50","exit"],["erin","20","enter"],["erin","30","exit"]]
Output: [[],["erin"]]
Sorted by time, Erin alternates enter and exit with no mismatch, and her entries at 0, 20 and 60 span exactly 60 minutes, which counts. Frank enters once and exits once.