Filter Strings and Extract Payment Details
Problem statement
Filter raw strings and extract normalized payment details.
Each record contains pipe-separated key=value fields. Fields may appear in any order. A valid payment record must contain exactly one of each required key:
id: one or more lowercase English letters, digits, or underscores;amount: a positive decimal integer with no sign;currency: exactly three uppercase English letters.
Extra keys are allowed and ignored. A record is invalid when a field lacks =, a required key is missing or repeated, or a required value fails its rule.
For every valid record, return id,amount,currency in input order. Preserve the decimal digits of amount exactly as written.
What the interview report shared
The reported internship OA used one progressive string-processing task with filtering and payment-detail extraction. The original delimiters, filters, malformed-input behavior, and output format were not preserved.
Function
extractPaymentDetails(records: String[]) → String[]Examples
Example 1
records = ["currency=USD|id=pay_1|amount=2500|note=ok","id=bad|currency=usd|amount=10","amount=75|id=pay_2|currency=EUR"]return = ["pay_1,2500,USD","pay_2,75,EUR"]The first and third records contain one valid value for every required key. The middle record is removed because its currency is lowercase.
Example 2
records = ["id=x|amount=9|currency=JPY|id=y","id=a|amount=001|currency=USD","id=b|amount=0|currency=USD"]return = ["a,001,USD"]The first record repeats id, and the last has a nonpositive amount. The valid record preserves 001.
Constraints
1 <= records.length <= 10^5.1 <= records[i].length <= 500.- Keys and values contain printable ASCII characters other than
|. - For this exercise, an empty field or empty key is malformed.