• + 0 comments

    I have used regex to solve this problem, and some python logics.

    I have created 3 differents patterns (1 for each condition, except the last one which check at the same time if the UID is exactly 10 characters).

    first condition pattern check if 2 uppercase (at least) are present or not.

    Note : ?. is a lookaround operators and it means anything before an uppercase. So "....A....". This format must be repeated at least twice : {2,}

    Exact same logics with digits 0-9

    And the last pattern, I think, is logic to understand, we only want a-zA-Z0-9 characters exactly 10 times.

    Then, we just have to check condition by condition.

    Here my code, I am pretty sure there is a simple way or more concise way to solve this problem, but, it works and the logics sounds good :

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import re
    
    T = int(input())
    
    UID_list = list()
    
    for _ in range(T):
        current_UID = input()
        UID_list.append(current_UID)
        
    # Patterns
    first_condition_pattern = r'^(?=(?:.*[A-Z]){2,}).*$'
    
    second_condition_pattern = r"^(?=(?:.*[0-9]){3,}).*$"
    
    third_condition_pattern = r"[a-zA-Z0-9]{10}"
    
    for element in UID_list:
        
        if len(set(element)) != len(list(element)):
            #print("Repeat character")
            print("Invalid")
    
        elif bool(re.match(first_condition_pattern, element)) == False:
            #print("Not 2 upper case minimum")
            print("Invalid")
        
        elif bool(re.match(second_condition_pattern, element)) == False:
            #print("Not 3 digits minimum")
            print("Invalid")
        
        elif bool(re.match(third_condition_pattern, element)) == False:
            #print("Not only alphanumeric character or not exactly 10 characters")
            print("Invalid")
        
        else:
            print("Valid")