Tuesday, December 10, 2019

Validating UID - Hacker Rank Solution

ABCXYZ company has up to  employees.
The company decides to create a unique identification number (UID) for each of its employees.
The company has assigned you the task of validating all the randomly generated UIDs.

Validating UID - Hacker Rank Solution


(.*[A-Z]){2,}
.
* matches any character (except for a newline).
[A-Z] matches a single character present in the range between A and Z (case sensitive).

(.*[0-9]){3,}
.
* matches any character (except for a newline).
[0-9] matches a single character present in the range between 0 and 9 (case sensitive)


.*(.).*\1+.*
.* matches any character (except for a newline).
\1+ matches the same text as the most recently matched by the 1st capturing group.


import re
for i in range(int(raw_input())):
    N = raw_input().strip()
    if N.isalnum() and len(N) == 10:
        if bool(re.search(r'(.*[A-Z]){2,}',N)) and bool(re.search(r'(.*[0-9]){3,}',N)):
            if re.search(r'.*(.).*\1+.*',N):
                print 'Invalid'
            else:
                print 'Valid'    
        else:
            print 'Invalid'
    else:
        print 'Invalid'

No comments:

Post a Comment

Powered by Blogger.