
    Design a fraud detection function that validates transaction IDs by ensuring each digit in the ID appears no more times than its own value, where each digit represents the maximum allowed security check count. For example, in a transaction ID of 12333, the digit 3 appearing three times is valid since it equals its value, while in 22222, the digit 2 appearing five times would be flagged as suspicious since it exceeds its value of 2.
    

    
def validate(n):
    """
    Design a fraud detection function that validates transaction IDs by ensuring each digit in the ID appears no more times than its own value, where each digit represents the maximum allowed security check count. For example, in a transaction ID of 12333, the digit 3 appearing three times is valid since it equals its value, while in 22222, the digit 2 appearing five times would be flagged as suspicious since it exceeds its value of 2.
    

    """
def validate(n):
    """
    Design a fraud detection function that validates transaction IDs by ensuring each digit in the ID appears no more times than its own value, where each digit represents the maximum allowed security check count. For example, in a transaction ID of 12333, the digit 3 appearing three times is valid since it equals its value, while in 22222, the digit 2 appearing five times would be flagged as suspicious since it exceeds its value of 2.
    

    """
    for i in range(10):
        temp = n
        count = 0
        while temp:
            if temp % 10 == i:
                count += 1
            if count > i:
                return False
            temp //= 10
    return True