Badge Records Without a Match
Updated
Problem statement
Given a log records of badge swipes at the door of a secure room, return two lists: the people who entered without exiting, and the people who exited without entering.
Each record is [name, action], where action is "enter" or "exit". The records are in time order. The room is empty when the log starts, and everyone must leave before it ends. Track each person as inside or outside:
- An
"enter"while the person is already inside means they left earlier without badging out, so they entered without exiting. They stay inside. - An
"exit"while the person is outside means they came in without badging in, so they exited without entering. They stay outside. - Anyone still inside when the log ends also entered without exiting.
Return [enteredWithoutExiting, exitedWithoutEntering]. Each list holds every matching name once, sorted in alphabetical order. A list can be empty, and the same person can be in both lists.
Function
findMismatchedRecords(records: String[][]) → List<List<String>>Examples
Example 1
records = [["Anna","enter"],["Ben","enter"],["Anna","exit"],["Ben","enter"],["Cara","exit"],["Ben","exit"]]return = [["Ben"],["Cara"]]Ben badges in twice without badging out in between, so he entered without exiting. Cara badges out while she is not in the room, so she exited without entering. Anna is fine.
Example 2
records = [["Dana","exit"],["Dana","enter"]]return = [["Dana"],["Dana"]]Dana badges out of an empty room, then badges in and never leaves before the log ends. She belongs in both lists.
Example 3
records = [["Eli","enter"],["Eli","exit"],["Eli","enter"],["Eli","exit"]]return = [[],[]]Every entry is followed by an exit, and the room is empty at the end, so both lists are empty.
Example 4
records = [["Finn","exit"],["Gus","enter"],["Finn","exit"],["Gus","enter"],["Gus","enter"]]return = [["Gus"],["Finn"]]Finn exits twice without being in the room, and Gus enters three times without leaving. Each name appears once in its list.
Constraints
1 <= records.length <= 105records[i].length == 2records[i][0]is an uppercase English letter followed by0to9lowercase English letters.records[i][1]is"enter"or"exit".
More WhatNot Phone Screen questions
- Adjacent Pair and Run RemovalPHONE SCREEN · Seen Nov 2026
- Merge Sorted Squares of Two ArraysPHONE SCREEN · Seen Nov 2026
- User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Knight Dialer SequencesPHONE SCREEN · Seen Oct 2026
- Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
- Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
- Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
- Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
- Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Bounded IPv4 FilterAmazon · PHONE SCREEN
- SimpleRDD Multiset IntersectionDatologyAI · PHONE SCREEN
- Vehicle Maintenance Event ReadinessWaymo · PHONE SCREENWaymo interview questions
- Summarize the Latest Event for Each DeviceOneTrust · PHONE SCREEN
- Project JSON Fields into a Target FormatBooking.com · PHONE SCREEN
- Employee Training StatusVanta · PHONE SCREEN
- Select Object by Key ExtremeBridge · PHONE SCREENBridge interview questions
- Group Names by DepartmentMastercard · PHONE SCREENMastercard interview questions
- AI Role: Collection with Add and Remove OperationsApple · PHONE SCREENApple interview questions