Monday, November 13, 2017

Remove characters occurring multiple times

A string S is passed as the input. The program must remove all characters which appear more than once. If all the characters in a string are occurring more than once, then print -1 as output.

Input Format:
The first line contains the value of S.

Boundary Conditions: 2 <= Length of S <= 100

Output Format:
The string with the characters occurring more than once removed.

Example Input/Output 1:
Input:
level
Output:
v
Explanation: l and e occur more than once. Hence they are removed.

Example Input/Output 2:
Input:
ababab
Output:
-1

Solution:
s,c=input(),0
for i in s:
    if s.count(i)==1:
        print(i,end="")
    else:
        c+=1
if count==len(s): print(-1)
Share: