Validate banknote serial numbers and sum the valid face values after a 1% tax

Quick Overview

Validate fixed-format banknote serial numbers (two uppercase letters, six digits, two uppercase letters), sum the face values of the valid notes, and return 99% of the total rounded down. It tests careful string validation, bounds checks before indexing, and exact integer rounding.

Validate banknote serial numbers and sum the valid face values after a 1% tax

Company: Box

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

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 ```python 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 ```text 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 $\lfloor 300 \cdot 0.99 \rfloor = 297$. ```text 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 $\lfloor 1000 \cdot 0.99 \rfloor = 990$. ```text 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.

Overview: Validate fixed-format banknote serial numbers (two uppercase letters, six digits, two uppercase letters), sum the face values of the valid notes, and return 99% of the total rounded down. It tests careful string validation, bounds checks before indexing, and exact integer rounding.

Box logo
Box
Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
3
0

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\lfloor 300 \cdot 0.99 \rfloor = 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\lfloor 1000 \cdot 0.99 \rfloor = 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.