Ordered Badge Entry and Exit Violations
Updated
Problem statement
Each row of records is [name,action], where action is enter or exit. Process the records in their given order and identify people whose badge history has entry or exit violations.
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.
For this exercise, assume everyone starts outside. After any enter, the person is inside; after any exit, the person is outside, including after an invalid repeated action. A person still inside at the end has an entry without an exit. Later valid events never erase a previously recorded violation.
Return exactly two rows: the first contains names with an entry without an exit, and the second contains names with an exit without an entry. For this exercise, assume each row contains unique names sorted lexicographically, names are case-sensitive, and an empty history returns [[],[]].
For this exercise, assume the two returned categories refer to violations of this ordered alternating flow, including repeated actions and a final open entry.
Function
badgeViolations(records: String[][]) → String[][]Examples
Example 1
records = [["Sarah","enter"],["john","exit"],["Sarah","enter"],["Mike","enter"],["Abdul","enter"],["Sarah","exit"]]return = [["Abdul","Mike","Sarah"],["john"]]Under the stated rules, Sarah's repeated entry is retained as a violation even after her exit. Mike and Abdul end inside; john exits while outside.
Example 2
records = [["u","enter"],["u","enter"],["u","exit"],["u","exit"]]return = [["u"],["u"]]Both repeated actions are violations even though the total entry and exit counts are equal.
Constraints
- For this exercise, assume
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 Coinbase interview questions
- Select Transactions with Child-Pays-for-Parent PackagesPHONE SCREEN · Seen Oct 2026
- Lexicographically Smallest Topological OrderPHONE SCREEN · Seen Apr 2022
- Longest Common Contiguous SubarrayPHONE SCREEN · Seen Nov 2021
- Justify Text to a Fixed WidthPHONE SCREEN · Seen Jun 2021
- Scheduled Payments with Account AliasesONSITE INTERVIEW · Seen Oct 2026
- Task Management SystemOA · Seen Sep 2026
- Cloud Compute Credits SystemOA · Seen Aug 2026
- Dynamic Fixed-K Score LeaderboardONSITE INTERVIEW · Seen Aug 2026
- Minimum Days for Fixed-Order Tasks with CooldownONSITE INTERVIEW · Seen Aug 2026
- Sliding-Window Averages as Reduced FractionsONSITE INTERVIEW · Seen Aug 2026
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