Find duplicate character in a given
string, there is one/two character which appears twice. Write a program to find
the character and return it.
Sample
Input & Output:
Input: placement
Output : e
Input: "array"
Output: ar
Solution:
#include<iostream>
using namespace std;
int main()
{
string s;
cin>>s;
int count[26]={0};
for(int i=0;i<s.size();i++)
count[s[i]-'a']++;
for(int i=0;i<s.size();i++)
if(count[s[i]-'a']>1)
{
cout<<s[i];
count[s[i]-'a']=0;
}
return 0;
}