Skip to content
Image
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • 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
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerRank Validating UID solution in Python

Image YASH PAL, 31 July 202417 January 2026

HackerRank Validating UID solution in Python – 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.

A valid UID must follow the rules below:

  • It must contain at least 2 uppercase English alphabet characters.
  • It must contain at least 3 digits (0 – 9).
  • It should only contain alphanumeric characters (a – z,A  – Z & 0 – 9).
  • No character should repeat.
  • There must be exactly 10 characters in a valid UID.
HackerRank Validating UID solution in python

HackerRank Validating UID solution in Python 2.

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'

Validating UID solution in Python 3.

# 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 Hackerrank Problems Solutions Python Solutions HackerRankPython

Post navigation

Previous post
Next post
HackerRank Python Solutions
Say “Hello, World!” With Python solution
Python If-Else problem solution
Arithmetic Operators problem solution
Python Division problem solution
Loops problem solution
Write a function problem solution
Print Function problem solution
List Comprehensions problem solution
Find the Runner-Up Score! problem solution
Nested Lists problem solution
Finding the percentage problem solution
Lists problem solution
Tuples problem problem solution
sWAP case problem solution
String Split and Join problem solution
What’s Your Name? problem solution
Mutations problem solution
Find a string problem solution
String Validators problem solution
Text Alignment problem solution
Text Wrap problem solution
Designer Door Mat problem solution
String Formatting problem solution
Alphabet Rangoli problem solution
Capitalize! problem solution
The Minion Game problem solution
Merge the Tools! problem solution
itertools.product() problem solution
collections.Counter() problem solution
itertools.permutations() problem solution
collections.Counter() problem solution
itertools.permutations() problem solution
Polar Coordinates problem solution
Introduction to Sets problem solution
DefaultDict Tutorial problem solution
Calendar Module problem solution
Exceptions problem solution
Collections.namedtuple() problem solution
Time Delta problem solution
Find Angle MBC problem solution
No Idea! problem solution
Collections.OrderedDict() problem solution
Symmetric Difference problem solution
itertools.combinations() problem solution
Incorrect Regex problem solution
Set .add() problem solution
itertools.combinations_with_replacement() problem solution
Word Order problem solution
Set .discard(), .remove() & .pop() problem solution
Collections.deque() problem solution
Compress the String! problem solution
Company Logo problem solution
Set .union() Operation problem solution
Piling Up! problem solution
Triangle Quest 2 problem solution
Iterables and Iterators problem solution
Set .intersection() Operation problem solution in python
Mod Divmod problem solution
Power — Mod Power problem solution
Maximize It! problem solution
Set .difference() Operation problem solution
Integers Come In All Sizes problem solution
Set .symmetric_difference() Operation problem solution
Set Mutations problem solution
Triangle Quest problem solution
The Captain’s Room problem solution
Check Subset problem solution
Check Strict Superset problem solution
Classes: Dealing with Complex Numbers problem solution
Class 2 — Find the Torsional Angle problem solution
Zipped! problem solution
Input() problem solution
Python Evaluation problem solution
Athlete Sort problem solution
Any or All problem solution
ginortS problem solution
Detect Floating Point Number problem solution
Map and Lambda Function problem solution
Re.split() problem solution
Validating Email Addresses With a Filter problem solution
Group(), Groups() & Groupdict() problem solution
Reduce Function problem solution
Re.findall() & Re.finditer() problem solution
Re.star() & Re.end() problem solution
Regex Substitution problem solution
Validating Roman Numerals problem solution
Validating Phone Numbers problem solution
Validating and parsing Email Addresses problem solution
Hex Color Code problem solution
HTML Parser — Part 1 problem solution
HTML Parser — Part 2 problem solution
Detect HTML Tags, Attributes and Attributes Values problem solution
XML 1 — Find the Score problem solution
Validating UID problem solution
Validating Credit Card Numbers problem solution
XML2 — Find the Maximum Depth problem solution
Standardize Mobile Number using Decorators problem solution
Validating Postal Codes problem solution
Decorators 2 — Name Directory problem solution
Matrix Script problem solution
Words Score problem solution
Arrays problem solution
Shape and Reshape problem solution
default Arguments problem solution
Transpose and Flatten problem solution
Concatenate problem solution
Zeros and One’s problem solution
Eye and Identity problem solution
Array Mathematics problem solution
Floor, Ceil, and Rint problem solution
Sum and Prod problem solution
Min and Max problem solution
Mean, Var, and Std problem solution
Dot and cross problem solution
Inner and Outer problem solution
Polynomials problem solution
Linear Algebra problem solution

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes
Advertisement