You are given a list of banknotes, each with a serial number and a face value. A serial number is considered valid if it meets all of the following rules:
-
It has exactly 10 characters.
-
The first two characters are uppercase letters (
A
-
Z
).
-
The next six characters are digits (
0
-
9
).
-
The last two characters are uppercase letters (
A
-
Z
).
For all banknotes with valid serial numbers, sum their face values. Then apply a 1% tax removal (multiply the sum by 0.99) and return the result rounded down to the nearest integer.
Function Signature
def counterfeit_currency(banknotes: list[list]) -> int:
Rules
-
Each
banknotes[i]
is a two-element list
[serial_number, face_value]
, where
serial_number
is a string and
face_value
is a positive integer.
-
Letters and digits are ASCII only: a letter means
A
to
Z
and a digit means
0
to
9
.
-
Each banknote is judged on its own. If the same valid serial number appears on two notes, both face values count.
-
Return
floor(0.99 * total)
, where
total
is the sum of face values over the valid notes. If no note is valid, return
0
.
Constraints
-
1 <= len(banknotes) <= 10^4
-
Each banknote is a pair
[serial_number, face_value]
.
-
1 <= face_value <= 10^6
-
1 <= len(serial_number) <= 20
-
serial_number
consists of uppercase letters, lowercase letters and digits.
Examples
Input: banknotes = [["AB123456CD", 100], ["XY654321ZW", 200], ["INVALID123", 500], ["AB12345CD", 300]]
Output: 297
"AB123456CD" and "XY654321ZW" match the pattern. "INVALID123" has 10 characters but a letter at index 2, and "AB12345CD" has only 9 characters. The valid total is 300, and ⌊300⋅0.99⌋=297.
Input: banknotes = [["AB000000CD", 1000], ["ab123456cd", 500], ["AB1234S6CD", 200]]
Output: 990
"ab123456cd" fails because its letters are lowercase, and "AB1234S6CD" fails because the character at index 6 is S. Only 1000 counts, and ⌊1000⋅0.99⌋=990.
Input: banknotes = [["QQ999999QQ", 150], ["QQ9999999Q", 40]]
Output: 148
Only "QQ999999QQ" is valid, since "QQ9999999Q" has a digit at index 8. The total is 150, and 0.99 times 150 is 148.5, which rounds down to 148.