You are given the attendance log of an office as a list of records in the order they happened. Each record says that an employee, identified by a unique name, either entered or exited the office.
Every employee must follow the flow enter → exit → enter → exit → .... The office is empty when the log starts, and every employee must have exited by the time the log ends. Looking only at the records of one employee:
enter is not followed by an exit, i.e. the next record of that employee is also enter (enter → enter) or there is no next record.exit is not preceded by an enter, i.e. the previous record of that employee is also exit (exit → exit) or there is no previous record.Find the names of all employees with entry violations and all employees with exit violations.
List<List<String>> findViolations(List<String> records)
"name,action", where action is "enter" or "exit", e.g. "Tara,enter".0: names of employees with an entry violation.1: names of employees with an exit violation.1 ≤ records.size() ≤ 100,0001 ≤ name.length() ≤ 20name is an uppercase English letter and all other letters are lowercase English letters.action is either "enter" or "exit".Input: findViolations(records = ["Rohan,exit", "Tara,enter", "Vikram,enter", "Tara,enter", "Pooja,enter", "Vikram,exit", "Pooja,exit", "Tara,exit", "Neha,enter", "Pooja,exit", "Rohan,enter", "Rohan,exit"])
Output: [["Neha", "Tara"], ["Pooja", "Rohan"]]
Explanation:
enter → enter → exit. It has enter → enter, so entry violation.enter. She is still inside when the log ends, so entry violation.exit → enter → exit. His first record is exit, so exit violation.enter → exit → exit. It has exit → exit, so exit violation.enter → exit. No violation.Input: findViolations(records = ["Kiran,enter", "Manav,enter", "Kiran,exit", "Kiran,enter", "Manav,exit", "Kiran,exit"])
Output: [[], []]
Explanation: Kiran (enter → exit → enter → exit) and Manav (enter → exit) both follow the correct flow, so both lists are empty.
Input: findViolations(records = ["Zoya,exit", "Zoya,enter", "Zoya,enter", "Zoya,exit", "Zoya,exit"])
Output: [["Zoya"], ["Zoya"]]
Explanation: Zoya's records are exit → enter → enter → exit → exit. The enter → enter part is an entry violation. The first exit and the exit → exit part are exit violations. Her name appears only once in each list.