Maximum Uncommon Characters

 Coding Problem Keys 

 Maximum Uncommon Characters 

 Problem Statement 

Given N strings as input, the program must print the string which has the maximum number of uncommon characters. If more than one strings have the same number of uncommon characters print the first occurring string.

 Boundary Condition(s) 

1 <= N <= 100

 Input Format 

The first line contains the value of N.
The next N lines contain a string each.

 Output Format 

The first line contains a string.

 Example Input/Output 1 

 Input 

4
tiger
umbrella
power
killer

 Output 

umbrella

 Explanation 

The common characters are e and r.
The uncommon characters are (t i g), (u m b l l a), (p o w), (k i l l).
Hence umbrella is the output.

 Example Input/Output 2 

 Input 

3
aaayz
yzbcd
cceyz

 Output 

aaayz

 Explanation 

The common characters are y and z.
The uncommon characters are (a a a), (b c d), (c c e).
Hence aaayz is the output.

 Solution 

 Programming Language: Python 3 Language 

z=[input().strip() for i in range(int(input()))]
x,s="",""
for i in z:
    x+=''.join(sorted(set(i)))
for i in z:
    for j in i:
        if x.count(j)==4 and j not in s:
            s+=j 
a,b,c=len(z[0])-len(s),len(s),z[0]
for i in z:
    if len(i)-b>a:
        c=i 
        a=len(i)-b
print(c)
#Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Integer & Alphabet Pair Pattern

Desktop Products

Pattern Printing Middle Letter - Odd Length String

Words Starting with Upper Case

GeeksForGeeks Mega Job-A-Thon

Matrix Columns - Largest Integer