Ordered Badge Entry and Exit Violations
Updated
Problem statement
Given records, return two lists of names: people with an entry without an exit, then people with an exit without an entry. Each row of records is [name,action], where action is enter or exit. Process the rows in their given order.
Everyone starts outside. A valid history alternates enter,exit,enter,exit,.... An entry while already inside means an exit is missing. An exit while outside means an entry is missing. After any enter the person is inside, and after any exit the person is outside, even if that action was a violation. A person still inside at the end has an entry without an exit. Later valid events never erase a violation already found.
Each list holds unique names in lexicographic order. Names are case-sensitive. If records is empty, return [[],[]].
Function
badgeViolations(records: String[][]) → String[][]Examples
Example 1
records = [["Arjun","enter"],["Riya","exit"],["Arjun","enter"],["Arjun","exit"],["Meera","exit"],["Kabir","enter"],["Meera","enter"],["Amit","enter"],["Meera","exit"],["Sneha","enter"],["Kabir","enter"],["Rahul","exit"],["Rahul","enter"],["Kabir","exit"],["Meera","enter"],["Meera","exit"],["Sneha","exit"],["Kabir","enter"],["Kabir","enter"],["Meera","exit"],["Kabir","exit"],["Kabir","exit"]]return = [["Amit","Arjun","Kabir","Rahul"],["Kabir","Meera","Rahul","Riya"]]Arjun and Kabir each enter twice in a row, and Amit and Rahul end inside, so they form the first list. Meera, Riya, Rahul and Kabir each exit at least once while outside, so they form the second list.
Example 2
records = [["Arjun","enter"],["Arjun","exit"]]return = [[],[]]Arjun enters and then exits, which is a valid history, so both lists are empty.
Example 3
records = [["Arjun","enter"],["Arjun","enter"],["Arjun","exit"],["Arjun","exit"]]return = [["Arjun"],["Arjun"]]Arjun's second enter comes while he is inside, and his second exit comes while he is outside, so he is in both lists.
Constraints
0 <= records.length <= 1000.- Each row has exactly two strings; the action is
enterorexit. - Names are case-sensitive alphanumeric strings with lengths from
1through30.
More Atlassian Phone Screen questions
- Merge Overlapping IntervalsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Tennis Court SchedulingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
- Longest Consistent Activity StreakPHONE SCREEN · Seen Sep 2026
- Music Player Operation SequencePHONE SCREEN · Seen Sep 2026
- Underline Shortest Unique SubstringsPHONE SCREEN · Seen Aug 2026
- Can a Dictionary Word Be Formed from Note Letters?PHONE SCREEN · Seen Feb 2026
- Word Path Moving Only Right or DownPHONE SCREEN · Seen Feb 2026
- Two Sum with an Ordered Index PairPHONE SCREEN · Seen Aug 2025
- Can You Finish the Teleporter Board?PHONE SCREEN · Seen Jul 2025
Similar questions at other companies
- Config Store with Priority OverridesMicrosoft · PHONE SCREENMicrosoft interview questions
- ID Allocator with Assign and ReleaseSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
- Feature Flag EvaluationCVS Health · PHONE SCREEN
- Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Network Endpoint or Cycle BoundaryOpenAI · OA · PHONE SCREENOpenAI 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