Problem · String
Counterfeit Currency
Learn this problemProblem statement
Box is validating attempted cryptocurrency payments. Each coin is represented by a serial number, and only serial numbers that satisfy every rule contribute value.
Serial-number rules
- The serial number contains between
10and12characters, inclusive. - The first
3characters are distinct uppercase English letters. - The next
4characters form a year from1900through2019, inclusive. - The following characters form exactly one allowed denomination:
10,20,50,100,200,500, or1000. - The final character is exactly one uppercase English letter.
Tax calculation
For a valid coin with denomination value, apply the 1% processing tax and round the remaining value down. Its contribution is floor(value * 99 / 100).
Complete countCounterfeit. Given the array serialNumber, return the sum of the taxed contributions of all valid serial numbers. Invalid serial numbers contribute 0.
Function
countCounterfeit(serialNumber: String[]) → intExamples
Example 1
serialNumber = ["AVG190420T","RTF20001000Z","QWER201850G","AFA199620E","ERT1947200T","RTY20202004","DRV1984500V","ETB2010400G"]return = 1702The valid denominations are 20, 1000, 200, and 500. After applying the tax, their contributions are 19, 990, 198, and 495.
The returned sum is 19 + 990 + 198 + 495 = 1702.
Constraints
- 0 < n ≤ 10^5
- 1 ≤ |serialNumber[i]| ≤ 14