FastPrepFastPrep
Problem Brief

Counterfeit Currency

OA

Box's Online Sales team is looking to expand their payment options to accept crypto currency. To ensure that they detect any attempts at fake payments, we need you to help our team validate each attempted crypto payment. You will help us identify bad currency by using a few rules. Each piece of crypto currency has a serial number that can be used to determine whether it is valid. The serial number also can be used to determine the value of the coin. A valid serial number will have the following characteristics:

  • The serial number is 10 ~ 12 characters.
  • The first 3 characters are distinct uppercase English letters.
  • The next 4 characters represent the year the coin was minted and will always be between 1900 and 2019 inclusive.
  • The next characters represent the coin value and may be any one of (10, 20, 50, 100, 200, 500, 1000).
  • The final character should be an uppercase letter of the serial number. The serial number must end with exactly one uppercase English letter only.
  • Please note - a crypto processing tax of 1% must be taken from each valid transaction. Our system cannot handle fractional coins, so we will need to round down to an integer.

    Below are a few serial numbers, determine the value of those with valid currency with the correct tax removed.

    Function Description

    Complete the function countCounterfeit in the editor below. Each element is a string that represents a transaction. The function must return an integer sum of values of valid currency with the processed tax removed from the transaction.

    The function is currently written, but we've been struggling to fix the bugs. The bugs will need your help fixing as of Q4 2022, so we can release this new feature! Debug the method below and fix the bugs you find. Once all the bugs have been fixed the method will pass all test cases and we can move forward with the feature release.

    countCounterfeit has the following parameter(s):

    1. serialNumber[serialNumber[0]...serialNumber[n-1]]: an array of strings

    1Example 1

    Input
    serialNumber = ["AVG190420T", "RTF200010002", "QWER201850G", "AFA199620E", "ERT1947200T", "RTY20202004", "DRV1984500V", "ETB2010400G"]
    Output
    1720
    Explanation
    Example 1 illustration
    In total, there are valid coins worth 20 + 1000 + 200 + 500 = 1720.

    Constraints

    Limits and guarantees your solution can rely on.

    • 0 < n ≤ 10^5
    • 1 ≤ |serialNumber[i]| ≤ 14
    public int countCounterfeit(String[] serialNumber) {
      // write your code here
    }
    
    Input

    serialNumber

    ["AVG190420T", "RTF200010002", "QWER201850G", "AFA199620E", "ERT1947200T", "RTY20202004", "DRV1984500V", "ETB2010400G"]

    Output

    1720

    Sign in to submit your solution.