Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank Validating UID solution in python

YASH PAL, 31 July 2024

In this Validating UID problem, ABCXYZ company has up to 100 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.

HackerRank Validating UID solution in python

Problem solution in Python 2 programming.

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'

Problem solution in Python 3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re

for _ in range(int(input())):
    u = ''.join(sorted(input()))
    try:
        assert re.search(r'[A-Z]{2}', u)
        assert re.search(r'ddd', u)
        assert not re.search(r'[^a-zA-Z0-9]', u)
        assert not re.search(r'(.)1', u)
        assert len(u) == 10
    except:
        print('Invalid')
    else:
        print('Valid')

Problem solution in pypy programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT

ids = []
line_num = int(raw_input())
while line_num:
  ids.append(raw_input());
  line_num -= 1;

import re

for id in ids:
  chars_count = {char:id.count(char) for char in id}
  upper = 0
  not_alnum = 0;
  dig = 0;
  for ch in id:
    if ch.isupper(): upper += 1
    if not ch.isalnum(): not_alnum = 1;
    if ch.isdigit(): dig += 1;

  if len(id) != 10: print 'Invalid'
  elif len(set(chars_count.values())) != 1: print 'Invalid'
  elif upper < 2: print 'Invalid'
  elif dig < 3: print 'Invalid'
  elif not_alnum: print 'Invalid'
  else: print 'Valid'

Problem solution in pypy3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re

def valid_uid(uid):
    if len(re.findall(r"[A-Z]", uid)) < 2 or 
            len(re.findall(r"[0-9]", uid)) < 3 or 
            not re.match(r"[A-Za-z0-9]{10}$", uid) or 
            len(set(uid)) != len(uid):
        return False
    
    return True
    
n = int(input())
for _ in range(n):
    uid = input()
    if valid_uid(uid):
        print("Valid")
    else:
        print("Invalid")

coding problems python

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes