String - Repeating Alphabets

 Problem Coding Keys 

 String - Repeating Alphabets 

 Problem Statement 

Given a string S as the input, print the distinct alphabets in S that occurs more than once. The alphabets must be printed based on the order of their occurrence in S.

 Input Format 

The first line contains S.

 Output Format 

The first line contains the distinct alphabets in S that occurs more than once.

 Boundary Condition(s) 

2 <= Length of S <= 200

 Example Input/Output 1 

 Input 

Apple

 Output 

p

 Example Input/Output 2 

 Input 

environment

 Output 

en

 Note: Max Execution Time Limit: 5000 millisecs

 Solution: 

 Programming Language: Python 3 Language 

a=input().strip();q=[]
l=[i for i in set(a) if a.count(i)>1]
for i in a:
    if i in l and i not in q:
        print(i,end="")
        q+=[i]
#Published By PKJCODERS

 Programming Language: C++ Language 

#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,x;
    cin>>s;
    map<char,int>m;
    for(int i=0;i<s.length();i++){
        m[s[i]]++;
        if(m[s[i]]==1)
            x+=s[i];
    }
    for(int i=0;i<x.length();i++){
        if(m[x[i]]>1)
            cout<<x[i];
    }
}
//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

Intelligent Robber

String Rotation Odd and Even Positions

Multiply By 2

Reverse String - Vowels Retain Same Position

Octal Equivalent of N

Even Integers - Even Positions