Wrote this function which takes two strings and outputs number of common characters. Can't get it to work with online compiler... Seems logically fine to me.
int commonCharacterCount(std::string s1, std::string s2) {
int stringCount1[26]{ 0 };
int stringCount2[26]{ 0 };
int charGet;
int total{ 0 };
for (auto i = 0; i < s1.length(); i++)
{
charGet = s1[i];
stringCount1[charGet - 97] = stringCount1[charGet - 97]++;
}
for (auto i = 0; i < s2.length(); i++)
{
charGet = s2[i];
stringCount2[charGet - 97] = stringCount2[charGet - 97]++;
}
for (auto i = 0; i < 26; i++)
{
total = total + min(stringCount1[i], stringCount2[i]);
}
return total;
}