Unique character string

Problem : https://hack.codingblocks.com/app/contests/1499/1506/problem

My Solution : https://ide.codingblocks.com/s/219554

Why only 2 testcases are passing ?

@vaishnavtannu Because your logic is wrong.
Here according to you code max value of ans can be 256 which is not the case, for eg take 2 strings both as “aa” and “aa”.

Try to think something else.

I have made some modifications in my code. Can you please check it now – https://ide.codingblocks.com/s/219554. For the test case aa aa it is giving correct output, i.e. 1

@vaishnavtannu
For better understanding, see this example
[“un”,“iq”,“ue”] -> All possible concatenations are “”,“un”,“iq”,“ue”,“uniq” and “ique”.
[“cha”,“r”,“act”,“ers”] -> Possible solutions are “chaers” and “acters”.

For [“aa”, “aa”] , answer is zero

Here the subsequence is the word to notice.

Tip:- Two string can join only if after join them the characters in the new string are not repeated. Also the string having repeated characters are of no use also.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

can anyone guide me
what’s wrong in my code / logic.

#include <iostream>

#include
#include <unordered_map>
using namespace std;
int strun(vector a)
{
int n = a.size();
string ans = “”;
unordered_map<char, bool> taken;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < a[i].size(); j++)
{
if (taken[a[i][j]] == 0)
{
ans += a[i][j];
taken[a[i][j]] = 1;
}
}
}
return ans.size();
}
int main()
{
vector a;
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
string str;
cin >> str;
a.push_back(str);
}
cout << strun(a) << endl;
return 0;
}
/*
3
ab
cd
ab
*/