Skip to content
Programming101
Programmingoneonone

Learn everything about programming

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

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

Topics we are covering

Toggle
  • Problem solution in Python 2 programming.
  • Problem solution in Python 3 programming.
    • Problem solution in pypy programming.
    • Problem solution in pypy3 programming.

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 solutions Python Solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • 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
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes