Common Alphabets N Strings

Common Alphabets N Strings:

Problem:

N string values are passed as input to the program. Each string will contain only the alphabets a-z in lower case. A given alphabet may be repeated any number of times. The program must print the count C of the alphabets that are present in all the N string values. 

Input Format: 

The first line contains N. Next N lines contain the N string values. 

Output Format: 

The first line contains C. 

Boundary Conditions: 

2 <= N <= 500 

1 <= Length of the string value <= 1000 

Example Input/Output 1: 

Input: 

mnppqqr 

ajkmnnm 

poormanagement 

Output: 

Explanation: 

Only 2 alphabets m and n are present in all the three string values.

Program:

n = int(input())
d = dict() 
for i in range(n): 
    s = set(input().strip())
    for j in s
        try:
            d[j] += 1 
        except
            d[j] = 1 

c = 0 
for i in d:
    if d[i] == n : 
        c += 1 
print(c)        

Comments

Popular posts from this blog

Pronic Integers in N - InfyTQ question

Count Strong Points - Accenture

Letters at position of multiples of a number