
    Write a function that analyzes a student performance metric where each digit represents a difficulty level (0-9), and its frequency represents correct answers at that level, to determine if the number of correct answers at each difficulty level is less than or equal to the difficulty level itself. For example, in metric 1222, difficulty level 2 appears three times, which would be invalid since 3 > 2, indicating too many correct answers at that difficulty level.
    

    
def validate(n):
    """
    Write a function that analyzes a student performance metric where each digit represents a difficulty level (0-9), and its frequency represents correct answers at that level, to determine if the number of correct answers at each difficulty level is less than or equal to the difficulty level itself. For example, in metric 1222, difficulty level 2 appears three times, which would be invalid since 3 > 2, indicating too many correct answers at that difficulty level.
    

    """
def validate(n):
    """
    Write a function that analyzes a student performance metric where each digit represents a difficulty level (0-9), and its frequency represents correct answers at that level, to determine if the number of correct answers at each difficulty level is less than or equal to the difficulty level itself. For example, in metric 1222, difficulty level 2 appears three times, which would be invalid since 3 > 2, indicating too many correct answers at that difficulty level.
    

    """
    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