Approach

  Blog    |     February 02, 2026

To solve the problem of identifying fake export licenses, we need to validate two key aspects of each license: its identifier format and its expiration date. The identifier must follow a specific pattern, and the expiration date must be in the future. Here's a step-by-step solution:

  1. Identifier Validation: The license identifier must start with "EX" followed by exactly 8 digits. Any deviation from this format makes the license fake.
  2. Expiration Date Check: The expiration date must be after the current date (October 15, 2023). Licenses expiring on or before this date are considered fake.
  3. Combining Checks: A license is fake if either the identifier is invalid or the expiration date is not in the future.

Solution Code

import re
from datetime import datetime
def find_fake_licenses(licenses):
    current_date = datetime(2023, 10, 15).date()
    fake_licenses = []
    for license in licenses:
        id_str = license['id']
        exp_date_str = license['expiration']
        # Check identifier format
        if not re.match(r'^EX\d{8}$', id_str):
            fake_licenses.append(license)
            continue
        # Check expiration date
        try:
            exp_date = datetime.strptime(exp_date_str, '%Y-%m-%d').date()
        except ValueError:
            fake_licenses.append(license)
            continue
        if exp_date <= current_date:
            fake_licenses.append(license)
    return fake_licenses

Explanation

  1. Identifier Validation: Using a regular expression (^EX\d{8}$), we check if the identifier starts with "EX" followed by exactly 8 digits. If not, the license is immediately marked as fake.
  2. Expiration Date Check: The expiration date string is parsed into a date object. If parsing fails (invalid date format), the license is fake. Otherwise, it's checked against the current date (October 15, 2023). If the expiration date is on or before this date, the license is fake.
  3. Result Compilation: Licenses failing either check are added to the result list, which is returned at the end.

This approach efficiently combines format and date validation to identify fake export licenses, ensuring correctness and robustness against invalid inputs.


Request an On-site Audit / Inquiry

SSL Secured Inquiry