Process Card Transaction Records
Problem statement
Each string in records is one unquoted CSV row with six fields:
payment_id,card_network,month,fee,currency,query_statusTrim surrounding whitespace from every field. The input rows are valid: payment IDs are unique, month uses YYYY-MM, fee is a nonnegative decimal integer, currency is exactly three uppercase English letters, and query_status is OPEN or CLOSED.
Remove every record whose payment_id appears in defaulterPaymentIds. Sort the remaining records by card_network and then by payment_id, both in ascending lexicographic order.
Return the retained records in the same six-field order, using the trimmed field values joined by commas.
Function
processCardTransactions(records: String[], defaulterPaymentIds: String[]) → String[]Examples
Example 1
records = ["p3,Visa,2024-09,30,USD,OPEN","p1,Amex,2024-08,20,USD,CLOSED","p2,Visa,2024-07,25,EUR,OPEN"]defaulterPaymentIds = ["p2"]return = ["p1,Amex,2024-08,20,USD,CLOSED","p3,Visa,2024-09,30,USD,OPEN"]Payment p2 is removed. Amex sorts before Visa, so p1 precedes p3.
Example 2
records = [" b2 , Visa , 2025-01 , 0 , USD , OPEN ","a1,Visa,2024-12,15,USD,CLOSED","c1,Mastercard,2025-02,9,GBP,OPEN"]defaulterPaymentIds = []return = ["c1,Mastercard,2025-02,9,GBP,OPEN","a1,Visa,2024-12,15,USD,CLOSED","b2,Visa,2025-01,0,USD,OPEN"]Fields are trimmed before serialization. Mastercard sorts before Visa, and the two Visa rows are ordered by payment ID.
Example 3
records = ["p1,Amex,2024-01,5,USD,OPEN","p2,Visa,2024-02,8,USD,CLOSED"]defaulterPaymentIds = ["p1","p2","missing"]return = []Both existing payment IDs are marked as defaulters. An unknown defaulter ID has no effect.
Constraints
0 <= records.length <= 100000.0 <= defaulterPaymentIds.length <= 100000.- Every record has exactly six comma-separated fields and contains no quoted commas.
- Payment IDs are unique, and every field has at most
100characters before trimming. - Every defaulter payment ID is nonempty, and the defaulter list contains no duplicates.
- The combined input length is at most
2 * 10^6.