string getLongestRegex(string a, string b, string c) {
int n = a.size();
vector<set<char>> candidates(n, set<char>());
for (int i = 0; i < n; i++) {
candidates[i].insert(a[i]);
candidates[i].insert(b[i]);
}
for (int i = 0; i < n; i++) {
if (a[i] != c[i]) {
candidates[i].erase(a[i]);
}
if (b[i] != c[i]) {
candidates[i].erase(b[i]);
}
}
string regex = "";
for (int i = 0; i < n; i++) {
if (candidates[i].empty()) {
return "-1";
}
if (candidates[i].size() == 1) {
regex += "[" + string(1, *candidates[i].begin()) + "]";
} else {
regex += "[";
for (char ch : candidates[i]) {
regex += ch;
}
regex += "]";
}
}
return regex;
}