Problem · Array
Identify Broken Customer Transactions
Learn this problemProblem statement
A payment pipeline records the customer name for every transaction it starts in initiatedCustomers and for every transaction it finishes in completedCustomers.
A customer is broken when the number of initiated records for that name differs from the number of completed records. Return every broken customer name exactly once, in lexicographic order.
Names are matched exactly and are case-sensitive. A name that appears in only one array is broken.
Function
findBrokenCustomers(initiatedCustomers: String[], completedCustomers: String[]) → String[]Examples
Example 1
initiatedCustomers = ["Ada","Bo","Ada","Cy"]completedCustomers = ["Ada","Bo","Cy"]return = ["Ada"]Ada has two initiated records but only one completed record. Bo and Cy have matching counts.
Example 2
initiatedCustomers = ["Mia","Noah","Mia"]completedCustomers = ["Noah","Mia","Liam"]return = ["Liam","Mia"]Liam appears only among completions, while Mia has one unmatched initiation. The result is sorted.
Constraints
0 <= initiatedCustomers.length, completedCustomers.length <= 100000.- Each name contains between
1and50ASCII letters. - The total number of characters across both arrays is at most
2000000.