We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I've had too many regex solutions in a row, so I decided to go a different way for this. I tried to focus on readability (and debugability).
importcollections# A valid UID must:## * Be exactly 10 characters in length# * Only contain alphanumeric characters (a-z, A-Z, 0-9)# * Contain at least 2 uppercase English alphabet characters# * Contain at least 3 digits (0-9)# * Not repeat any characterdefvalidate_uid(uid):iflen(uid)!=10:returnFalseifnotall([c.isalnum()forcinuid]):returnFalseifsum([c.isupper()forcinuid])<2:returnFalseifsum([c.isdigit()forcinuid])<3:returnFalseifmax(collections.Counter(uid).values())>1:returnFalsereturnTruet=int(input())for_inrange(t):uid=input()is_valid=validate_uid(uid)message='Valid'ifis_validelse'Invalid'print(message)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Validating UID
You are viewing a single comment's thread. Return to all comments →
I've had too many regex solutions in a row, so I decided to go a different way for this. I tried to focus on readability (and debugability).