Monday, June 5, 2017

Chars To Remove For Same String Value

N string values S1, S2, S3, SN are passed as input to the program. Values of S1, S2, S3, SN are such that if one character is removed from each of these string values, then the resulting string values are equal (same). The characters to be removed from the string values named C1, C2, C3, CN will be different for each string.

Input Format: 

The first line will contain the value of N. The next N lines will contain the values of strings S1 to SN.

Boundary Conditions: 

2 <= N <= 10 Length of string SN is from 2 to 200

Output Format: 

The first line will contain the characters C1, C2, C3, .. CN to be removed from each of these string without any space between them.

Example Input/Output : 

Input:
2
bmanabgerb
manasgsesr

Output:
bs

Explanation:
If the character b is removed from the first string, it becomes manager. If the character s is removed from the second string, it becomes manager. Hence bs is printed as output.

Solution:

n = int(input())
nstring = [] 

for i in range(n):
    nstring += set(list(input().strip()))   

count = [0]*26

for char in nstring:
    count[ord(char)-ord('a')]+=1   

for char in nstring:
    if count[ord(char)-ord('a')]==1:
         print(char,end='')
Share: