function hasCharWithExactlyTwoOccurrences(line) {
const charCounts = Array(256).fill(0);
for (let i = 0; i < line.length; i++) {
charCounts[line.charCodeAt(i)]++;
}
for (let i = 0; i < 256; i++) {
if (charCounts[i] === 2) {
return true;
}
}
return false;
}
function filterLines(lines) {
const result = [];
for (let i = 0; i < lines.length; i++) {
if (hasCharWithExactlyTwoOccurrences(lines[i])) {
result.push(lines[i]);
}
}
return result;
}
// Example input
const input = [
"asdf",
"fdas",
"asds",
"d",
"fm",
"dfaa",
"aaaa",
"aabb",
"aaabb"
];
const result = filterLines(input);
console.log(result);
CmZ1bmN0aW9uIGhhc0NoYXJXaXRoRXhhY3RseVR3b09jY3VycmVuY2VzKGxpbmUpIHsKICAgIGNvbnN0IGNoYXJDb3VudHMgPSBBcnJheSgyNTYpLmZpbGwoMCk7IAoKICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGluZS5sZW5ndGg7IGkrKykgewogICAgICAgIGNoYXJDb3VudHNbbGluZS5jaGFyQ29kZUF0KGkpXSsrOyAKICAgIH0KCiAgICBmb3IgKGxldCBpID0gMDsgaSA8IDI1NjsgaSsrKSB7CiAgICAgICAgaWYgKGNoYXJDb3VudHNbaV0gPT09IDIpIHsKICAgICAgICAgICAgcmV0dXJuIHRydWU7IAogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gZmFsc2U7IAp9CgpmdW5jdGlvbiBmaWx0ZXJMaW5lcyhsaW5lcykgewogICAgY29uc3QgcmVzdWx0ID0gW107CiAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxpbmVzLmxlbmd0aDsgaSsrKSB7CiAgICAgICAgaWYgKGhhc0NoYXJXaXRoRXhhY3RseVR3b09jY3VycmVuY2VzKGxpbmVzW2ldKSkgewogICAgICAgICAgICByZXN1bHQucHVzaChsaW5lc1tpXSk7IAogICAgICAgIH0KICAgIH0KICAgIHJldHVybiByZXN1bHQ7Cn0KCi8vIEV4YW1wbGUgaW5wdXQKY29uc3QgaW5wdXQgPSBbCiAgICAiYXNkZiIsCiAgICAiZmRhcyIsCiAgICAiYXNkcyIsCiAgICAiZCIsCiAgICAiZm0iLAogICAgImRmYWEiLAogICAgImFhYWEiLAogICAgImFhYmIiLAogICAgImFhYWJiIgpdOwoKY29uc3QgcmVzdWx0ID0gZmlsdGVyTGluZXMoaW5wdXQpOwpjb25zb2xlLmxvZyhyZXN1bHQpOwo=